Hello Zola
28 January, 2025 - Categories: Zola - Tags: templates, Tera, Zola themes, Zola documentation, RSS, static site generators
By Steven Rosenberg
I have been experimenting with Zola sites pretty heavily this past week, creating and destroyed slightly south of 10 of them.
I have been a Hugo user for a few years at this point, so the concept of a static site generator that runs with a single binary file is something I'm comfortable with. I tend to find Hugo themes puzzling. I want to know how the pages come together so I can make the changes I want. Maybe Zola will provide that.
The one thing that users talk about is the difference in the templating language between Hugo and Zola. Plus Zola is supposed to be a simpler system. Whether that's by design, or just because it's a younger project with fewer developers, I don't know.
After looking at a couple dozen Zola themes, I tried a few out. One thing I'm discovering from looking at themes is that you can modify one by pulling ideas and code from another.
My theme requirements are:
- Simple, readable design
- Not heavy with JavaScript
- Not too geeky (as in don't show the Markdown
#
in post titles) - List at least a few posts on the home page
- Has working RSS (a surprisingly tall order, though I now know why), preferably with full text
- Has pages for a post archive, tags and categories
For now I'm using the Hook theme. It hits most of these requirements pretty well, though it won't render an RSS feed until I figure out how to update the code.
One of the cool features of Zola is the ability to override the templates in your theme by dropping files with the same template names and paths into your project installation's template file (in your local directories). I copied page.html
from /my-local-zola-directory/themes/zola-hack/templates
to /my-local-zola-directory/templates
, and from there I added the code needed to make an author's name appear on posts. I started with code from the after-dark theme and added a line so the global author (set in config.toml
) would appear.
Here is the code I added to /templates/page.html
:
<p class="secondary small">
{% if page.extra.author %}
By {{ page.extra.author }}
{% elif config.extra.author %}
By {{ config.extra.author }}
{% else %}
By {{ config.author }}
{% endif %}
</p>
That was enough to get my byline on this post.
To explain the code, it's classic if/else if/else
logic that goes in this order:
page.extra.author
is displayed if this code is in the front matter of the post:
+++
[extra]
author = "Rex Reed"
+++
I haven't tested it yet, but I assume that config.extra.author
displays if that same code above is in config.toml
.
And what's displaying on this post (for now anyway) is config.author
, which is in config.toml
like this:
author = "Rex Reed"
The Zola documentation for Page is very helpful, especially in terms of what you can do with front matter on a post.
Another page on the Zola documentation that I have been referring to is Configuration, which goes over things that you can put in config.toml
. It lists all the defaults, which really helped me. That's where I learned how to tell Zola to generate RSS feeds and set an author name.
I also learned from the Configuration page that if you flip from false to true on external_links_target_blank = false
, all of your links set with Markdown will automatically be coded with target=_blank
and rel="noopener"
and will open in a new browser tab when clicked.
Another thing this page tells me is that the built-in search is pretty nice, and in a way I'm sorry my current theme isn't using it. I did try it with the after-dark theme, and it is an impressive feature.
The [slugify]
section on the Configuration documentation page lists this Zola default:
# Whether to remove date prefixes for page path slugs.
# For example, content/posts/2016-10-08_a-post-with-dates.md => posts/a-post-with-dates
# When true, content/posts/2016-10-08_a-post-with-dates.md => posts/2016-10-08-a-post-with-dates
paths_keep_dates = false
Once I saw this, I started doing my dates in file names like this — 2025-01-29
— instead of the way I usually do them: 2025_0129
. That cleaned up my URLs right away.
It's interesting that the Hugo Bear Blog theme that I'm using in Hugo right now also cuts off the dates (which are on most of the files in my usual format (2025_0129
).
I think this is the code in hugo.toml
that makes this happen (but I can't be sure until I toggle it):
[permalinks]
blog = "/:slug/"
tags = "/blog/:slug"
It was quite a discovery with Hugo Bear Blog that this is something you could easily do. I really like having the dates in the file names because it helps me know how old a post is on my local computer without needing to open it and look at the date. But it's redundant on the live site where the blog generator puts dates on everything and renders it in order.
I'm glad this is the default in Zola (and works when you code the dates right in your source files).
Back to my RSS issue with Zola: I think I can coax the Hook theme into rendering an RSS feed. I know what the problem is: the options for RSS feeds in Zola changed in the 0.19 release, and there is old code in the theme. But can I fix it? I will try.