Keep images & content together

Resurrecting this thread because… relevant.

After some experimentation and based on what others have shown, you can put assets along with content files but they have to follow a certain structure format.

Content and Asset on same level

content
    - blog
        - post.md
        - post.png

This also works if the content and asset are on the same level but in their own sub-directory:

content
    - blog
        - post        
            - index.md
            - post.png

But! The content file has to have the name of index.md or else you’ll double stack on the directories in the built page (/blog/post/post/).

Both of these have the added benefit of allowing functioning markdown previews with graphics (assuming they are not done with shortcode) in editors that feature that, and also in GitHub previews.

However

If you use permalinks on your page, this will make it all come crashing down. The content will render but none of the assets referenced in the content will. The content gets the new permalink name but the assent is copied directly over in the directory structure name. There are really bad workarounds but it’s a problem. Maybe there is a function or something I’m missing that would make this work out… but I’m not aware of it. There is quite a contentious issue here https://github.com/gohugoio/hugo/issues/1199 but it points out the problem. It was continued less contentiously here https://github.com/gohugoio/hugo/issues/1768 .

What might be the way forward on this?

1 Like