Since I have converted my blog to Zola, I started using assets a little bit more in the posts. I am still not sure if it is the right thing, but for now it helps me convey information in addition to text.

To embed a photo into the post, there are at least two main options available in Zola: static assets and asset colocation. Using static assets is more suitable for icons and logos, generally for assets that are shared among multiple posts, so we explore the second option, the asset colocation.

The colocation roughly means that the page and assets it requires are located in the same directory tree. Usually, the post is a .md file located somewhere near the top of the content/ directory. Does it mean we should place photos there? Wouldn't it be a mess, so many markdown files and images together? Well this is the reason to make a dedicated directories. The exact same page can exist in the two locations (but not both). Either as a standalone file:


Or in the dedicated directory, as an


Colocating an asset simply means that the image is placed in the posts dedicated folder alongside it and referenced from the post:


There is more going on under the hood, but Zola docs have it covered. What I want to focus on is the process of getting from the first option to the second one. This happens to me, when I want to add the picture into the existing older post when updating it, or when I start writing the post and then I realize I need to add an asset to it. Basically, it happens quite often.

What needs to be done then are these three steps in succession:

  1. Get the filename of the post without it's .md extension
  2. Create a folder with the name of the file (if output paths are used for slugs)
  3. Move the post inside it as

I got annoyed the first time I had to do this by hand, so I wrote this script to do the "folderize" steps for me:


fullname=$(basename -- "$1")

mkdir "$filename"
mv "$fullname" "$filename/"

Put this script into the content/ where all your .md files are located as and make it executable via chmod +x It can then be run as follows:


There is one last thing that has to be done - making sure this script won't get copied into the public/ folder when running zola build. For this purpose, the ignored_content configuration option is available for config.toml:

ignored_content = ["*.sh"]

That's it!