from Hugo to Zola

2023-02-16

I recently switched this blog from hugo to zola. The latter is more permissive on mixing html and markdown content. It's also written in rust, a language I use to practice (as opposed to go).

I took this opportunity to design a theme for it, mostly made of strings. The idea is to stick to the newspaper format. I hope you like it ! It might behave weird with short paragraphs though ...

Tweaks

In the process, I needed a way to add optional comments to a taxonomy I use to sort my posts : tags. Based on a discussion on the zola forum, I come up with the following solution :

<!-- inside templates/tags/single.html -->
{% set tag_data = load_data(path="content/_tags.yml") -%}
{% if tag_data[term.slug] -%}
    <div class="description">
        {{ tag_data[term.slug].description | markdown() | safe }}
    </div>
{% endif -%}
# content/_tags.yml
html:
  description: |
    This is the HTML tag multiline description.
    ## Subtitle
    > Quote someone famous here.
casual:
  description: Casual posts, not connected to the rest.

Now, when you open the html tag page, you see the description that I filed inside /_tags.yml. I was looking for a way to unpublish this file while still watch it when using zola serve, but in the end why bother ? This is public data anyway.

Also, the description for a tag is not required. That way, you may add tags by simply mentioning them in a post.

The _tags.yml file is mandatory though. We could make it optional with the required=false option to load_data(), but you wouldn't get any error from zola in that case, which is generally against the Static Site Generator spirit.

If you think about it, an optional tags.yml would let users have surprises with that - like not commiting that file and wondering why there's no description in tags on the website.