I’ve got the typical /posts folder and it’s referencing images using ‘/images/img.png’ and it all works nicely in the Hugo Server run. I look at the locally built files and they all seem to have the full base URL + relative paths in them. However, after I actually publish the urls are all broken, it becomes ‘https://site.com/posts/images/img.png’. I don’t understand why it’s started to use a relative path?
Please post a link to the public repository for your site. See:
https://discourse.gohugo.io/t/requesting-help/9132
Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick
git clone
on your repo, then runhugo server
in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.
If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.
It works using Hugo Server, that’s part of the issue.
I understand.
If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.
I’m new to Netlify too and I’ve just discovered the download site button
So I’ve checked out the published code and sure enough the relative URLs are broken;
style=background-image:url(images/Background.PNG)
whereas previously the full url was there or /images…
Oddly since restarting I’m seeing the same thing when running Hugo Server and I’m getting the same missing images. So it’s one of those, “I’ve not changed anything” moments where something has changed, but I’ve no idea what.
Finally I’ve got there. It’s a combination of issues.
- Hugo vs. Hugo Server. I’d left Hugo Server running during the whole development process. What I’ve now realised is that isn’t the best idea. There are changes that the auto-watcher just doesn’t do a great job with. One of these was a change to a template that altered the URL address. I.e. the change occurred but the updated files using by ‘Server’ didn’t take the change. Once I’d stopped Server, built and restarted Server the problem URLs were exposed in the test site too
- Old version of Hugo. Somehow I’d got a config with a really old version of Hugo that seemed to work ok locally but blew up during publish. This resulted in errors in some of the theme code dealing with…yes URLs. In a panic I’d changed the code to get the publish working. Then I updated the config versions and put the code back…or so I thought. I’d tested on the local server and it was fine…or so I thought - see (1)
So after downloading the published site I could track down the problem, corrected it and restarted Hugo Server and tested the fix. Now my images are correct
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.