I’m new using Hugo and I have a problem.
I’m including images in my post like this
![JCM](James_Clerk_Maxwell.png)
with the images being saved in static/
The images display correctly in the main page of the website – as a post summary – but unexpectedly disappear (like a broken reference) as far as I access the full article.
I can’t figure out what’s going on, I tried saving the images together with the .md files in content/post/ file but (obviously?) nothing changes.
So, what am I doing wrong?
thanks in advance
You need to figure out what it means to not specify a path to an asset, because that’s what you’re doing. Look at the page source, and see if that path makes sense on the top page, versus a page/in/an/urlpath.
For instance, if you save your images say in static/img
, how would you need to specify their paths? What’s the difference between saying ![blah](/img/the_image.jpg)
and ![blah](img/the_image.jpg)
.
ok, may be I figured it out, I need the absolute url. if I’m right, say for example my website url is www.example.com/blog and my images are stored in static/, then I can specify the absolute url of an image as
![JCM](/blog/James_Clerk_Maxwell.png)
and this way the image displays fine both in the excerpt and in the full article body.
You’re on the right track. Specifying the url absolutely means “go find it here” no matter where you are in the site.
thank you for your help, now I have a better view of how Hugo handles images
Glad to hear. Relative vs Absolute paths/urls are not Hugo per se, but rather HTML basics, e.g.: https://www.w3.org/TR/WD-html40-970917/htmlweb.html
It’s just converting what you specify into code, in an unsurprising way.