You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I like the idea of having my images close to my content so I create my articles like this:
post/my-post.md
post/images/my-post-img.png
This displays the images on the single template when ugly urls are turned on but does not display it on the list pages or on any page when ugly urls are turned off. The relative path for the image never gets transformed even with canonifyurls turned on. Maybe there is a setting I am messing?

I see issue #147 had a discussion that might be related to this. The images are being copied but I am not getting the correct urls in the generated pages.
Any thoughts on this?
Reacted by mendhak, Jon Ross, Nicolas Hoizey, Cody, bademux, 涼宮ハルヒ, Henry, Ruslan Nasonov, Feng Yu, Kirill Aristov and 3 more
I would send a pull request but the go code makes me feel dumb. But seriously great to see @spf13 take up this issue. I know it complicates rendering because the link to the image would vary based on the final path of the page it is rendered on.
@spf13 have you got some ideas on how to implement this? we need it for the Docker docs, but pointers will get me up to speed faster :) (its on my list of things for the next 4 days :)
@jygastaud please take a look at the original issue again. If you only ever display images on the actual post page then you can work around it. However, if your list pages display posts with images where the image is located relative to the content then the image will not display. Hugo would probably need to take the mark down and write different urls to the same asset based on the context of the page render.
For example, your list page is www.yoursite.com/blog/ and it has your last 3 posts. A post at www.yoursite.com/blog/mypost.html with a relative image in /blog/images/img1.jpg can use a relative url in mypost.html to reference that image but that url will be incorrect for displaying your last 3 posts. It also gets tricky when you think about ugly vs no ugly urls. My hope was that Hugo could compensate for these different nuances and always write the correct url to the asset. I hope that clarifies it.
This issue gets more complicated when permalinks are used. For now I've just turned off permalinks so I can put images in the same folder as my content. It'd be good if the images gets copied along to the permalink folder structure instead of just the generated HTML file. Thanks!
Hi guys,
how to make this work with both Hugo and Github?
I have my documentation in markdown with images in the same folder. I would like to render it both with Hugo and Github...
I use Hugo V0.38 with bundles.
If I understood, I need to add some code in the markdown, such as:
{{ $logo := .Resources.GetByPrefix "logo" }}
But this won't work with Github.
Reacted by Henry, raphaelmaenle, Bevan Stanely, V and Michael Kolb
@cdupont obviously hugo shortcodes aren't supported in GitHub and probably never will be
one should never use them if one wishes to maintain portability
For those still looking for a solution to this issue (as it is not documented in the hugo docs) I will leave a solution here.
To achieve relative image paths in Hugo in markdowns files, you should organize your content using Hugo's newish Page Bundles structure, specifically Leaf Bundles. This requires using an index.md file (not to be confused with _index.md used in branch bundles).
You are probably used to writing posts inside of a markdown file with the name of the file as the post title , for example post_about_blah.md and blah_blah_post.md. And linking images from the static/ directory.
In the leaf bundle directory tree example above, index.md contains the "words" of your post and the directory in which index.md is (in our case content/posts/post_about_blah and content/posts/blah_blah_post) will be the generated url. The images will be rendered to to following links
Hi, I like the idea of having my images close to my content so I create my articles like this:
post/my-post.md
post/images/my-post-img.png
This displays the images on the single template when ugly urls are turned on but does not display it on the list pages or on any page when ugly urls are turned off. The relative path for the image never gets transformed even with canonifyurls turned on. Maybe there is a setting I am messing?

I see issue #147 had a discussion that might be related to this. The images are being copied but I am not getting the correct urls in the generated pages.
Any thoughts on this?
I find a feasible method: just follow this office tutor, and change the hook, here is my render-image.html
If you need ref a image link with http://xxxx, you need link it like this: 
Activity
bep commentedon Jul 2, 2015
This is currently not possible, but it is (or should be) in front of @spf13's brain ...
Currently you have to have to path relative to the context root (/post/images/...).
garvincasimir commentedon Jul 2, 2015
I would send a pull request but the go code makes me feel dumb. But seriously great to see @spf13 take up this issue. I know it complicates rendering because the link to the image would vary based on the final path of the page it is rendered on.
tcurdt commentedon Aug 9, 2015
I would love to have support for
and I want would like that to appear in the output as
tcurdt commentedon Aug 9, 2015
This actually seems to be working out of the box now.
Getting rid of "posts" folder is a problem though. A work around is to use:
which isn't quite the same thing though.
SvenDowideit commentedon Sep 10, 2015
@spf13 have you got some ideas on how to implement this? we need it for the Docker docs, but pointers will get me up to speed faster :) (its on my list of things for the next 4 days :)
SvenDowideit commentedon Sep 14, 2015
initial version added in #1398
AlexZeitler commentedon Jan 14, 2016
Is there any progress on using images in markdown relative to content?
jygastaud commentedon Jan 14, 2016
@AlexZeitler : As suggest in #147 I'm using the following workaround.
Contents are in
content/project/my-content/index.mdfolderImages are stored in
static/project/my-content/my-image.pngfolderAnd in my markdown I can do
Hugo just will copy the structure without the first "static" folder so generation the html file will have acces to the image.
Hope it helps!
AlexZeitler commentedon Jan 14, 2016
@jygastaud Thanks for your reply.
I created this structure now:
In the md I referenced it this way
I also tried
None did work.
jygastaud commentedon Jan 14, 2016
That's weird.
That works for me. See jygastaud/jygastaud.github.io@a415264 which result to http://gastaud.io/article/entityconnect-d8/conversion-form-instance/
You can see structure here : https://github.com/jygastaud/jygastaud.github.io/tree/source
garvincasimir commentedon Jan 15, 2016
@jygastaud please take a look at the original issue again. If you only ever display images on the actual post page then you can work around it. However, if your list pages display posts with images where the image is located relative to the content then the image will not display. Hugo would probably need to take the mark down and write different urls to the same asset based on the context of the page render.
For example, your list page is www.yoursite.com/blog/ and it has your last 3 posts. A post at www.yoursite.com/blog/mypost.html with a relative image in /blog/images/img1.jpg can use a relative url in mypost.html to reference that image but that url will be incorrect for displaying your last 3 posts. It also gets tricky when you think about ugly vs no ugly urls. My hope was that Hugo could compensate for these different nuances and always write the correct url to the asset. I hope that clarifies it.
jygastaud commentedon Jan 15, 2016
@garvincasimir oh sorry I missed the part that explains that it works on single page but not on list :/
Sorry for the noise.
wysie commentedon Jun 28, 2016
This issue gets more complicated when permalinks are used. For now I've just turned off permalinks so I can put images in the same folder as my content. It'd be good if the images gets copied along to the permalink folder structure instead of just the generated HTML file. Thanks!
24 remaining items
✨ Implement Page bundling and image handling
✨ Implement Page bundling and image handling
✨ Implement Page bundling and image handling
cdupont commentedon Apr 12, 2018
Hi guys,
how to make this work with both Hugo and Github?
I have my documentation in markdown with images in the same folder. I would like to render it both with Hugo and Github...
I use Hugo V0.38 with bundles.
If I understood, I need to add some code in the markdown, such as:
But this won't work with Github.
venky999 commentedon Sep 15, 2020
Any thoughts on how it works on both GitHub and Hugo
RMStoica-zivver commentedon Sep 16, 2020
@cdupont obviously hugo shortcodes aren't supported in GitHub and probably never will be
one should never use them if one wishes to maintain portability
nhoizey commentedon Sep 16, 2020
If there is no Hugo based solution, I wonder if you could:
It should work well with a few pages, but probably be pretty slow with many.
cdupont commentedon Sep 16, 2020
Actually, I got it working both in Github and vanilla Hugo.
See here for example: https://github.com/Waziup/waziup.io/blob/master/content/documentation/wazidev/sensors/index.md
I address the images like this:
The images are showing in Github.
nhoizey commentedon Sep 16, 2020
@cdupont perfect! 👍
sn0ot commentedon Dec 31, 2020
For those still looking for a solution to this issue (as it is not documented in the hugo docs) I will leave a solution here.
To achieve relative image paths in Hugo in markdowns files, you should organize your content using Hugo's newish Page Bundles structure, specifically Leaf Bundles. This requires using an
index.mdfile (not to be confused with_index.mdused in branch bundles).You are probably used to writing posts inside of a markdown file with the name of the file as the post title , for example
post_about_blah.mdandblah_blah_post.md. And linking images from thestatic/directory.Images would be rendered as such:
http://examplesite.com/images/picture_1.jpghttp://examplesite.com/images/picture_2.jpghttp://examplesite.com//images/picture_3.jpghttp://examplesite.com//images/picture_4.jpghttp://examplesite.com//images/picture_5.jpghttp://examplesite.com//images/picture_6.jpgAnd therefore, images would have to be linked from inside the markdown posts as such:
Now you have to keep track of which image goes with which post, no name conflicts, etc.
To link images in your markdown file relative to your post, consider the following leaf bundle directory tree:
In the leaf bundle directory tree example above,
index.mdcontains the "words" of your post and the directory in whichindex.mdis (in our casecontent/posts/post_about_blahandcontent/posts/blah_blah_post) will be the generated url. The images will be rendered to to following linkshttp://examplesite.com/posts/post_about_blah/picture_1.jpghttp://examplesite.com/posts/post_about_blah/images/picture_2.jpghttp://examplesite.com/posts/post_about_blah/images/picture_3.jpghttp://examplesite.com/posts/blah_blah_post/picture_1.jpghttp://examplesite.com/posts/blah_blah_post/images/picture_2.jpghttp://examplesite.com/posts/blah_blah_post/images/picture_3.jpgTherefore inside of the respective
index.mdfiles you can link to images as follows:NOTE: I made a poor choice of directory names and it looks like linking is the almost the same - so read carefully :)
ACupofAir commentedon Dec 5, 2021
I find a feasible method: just follow this office tutor, and change the hook, here is my render-image.html
If you need ref a image link with http://xxxx, you need link it like this:
github-actions commentedon Jan 14, 2022
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.