š„ From Hugo to Zola
Why Are We Here Again?
While I outlined my earlier selection of Hugo as the static-site-generator of choice in a previous post, itās finally time to admit that Go and I arenāt getting on. Itās not you, itās me (except itās totally you.)
And itās more than a little Rust, to be honest.
So, having failed miserably to write anything actually worth publishing (which does sound like rather a grandious overestimation of my previous posts) in over eighteen months, itās time to do what we all do and change the underlying framework so I can hack around and then then write about it in a weird, meta fashion.
Zola, I Missed You (Sort of.)
Back to Zola! My initial choice first time around, before becoming inexplicably over-optimistic regarding Go, Iāve been toying with the shift for far too long so back we wentā¦
It was a, shall we say, inauspicious start.
I followed the First Steps with Zola documentation to the letter, I swear.
I ran zola initā¦
, created my first.md
and second.md
blog posts, populated my templates
butā¦it didnāt work.
Running zola serve
span up the local webserver, rendering /blogs
; visiting /blogs/first
showed the contents of the relevant post perfectly well. But links to the latter were not appearing in the former.
Specifically, in this bit of the blog.html
content:
{% for page in section.pages %}
<li><a href="{{ page.permalink | safe }}">{{ page.title }}</a></li>
{% endfor %}
ā¦the section.pages
variable was empty. Displaying the contents with {{ section.pages }}
gave nothing more than a disheartening []
.
Iād love to say I got to the bottom of it but alas, no. After repeated copy-and-pastes of the documentation my list of blogs remained empty. Iāll probably repeat the exercise and either log a bug or confirm my ineptitude when Iām done documenting the latter here.
Taking a different approach and stripping back the metadata in each file, Zola thankfully started complaining about missing templates and the resulting errors largely hand-held me through the necessary additions.
The standard templates are documented in the relevant section of the documentation and, after adding those (rather than those described in the Overview documentation), voilĆ : our section began presenting the expected list of pages.
To implement a site structurally like its predecessor, the only templates specifically required were index.html
(to cover the home-page; functionally this is a section page but as weāve no other sections, the main page fulfils that role) and page.html
(to cover the individual blog posts.)
To Theme or Not to Theme?
I will not use ZOLA.386; I will not use ZOLA.386ā¦
I really want to use ZOLA.386.
Iāll admit that the themes available for Zola arenāt as many an multifarious as those of Hugo but they nevertheless cover most simple requirements.
That said, I opted to implement the templates from scratch manually using Bootstrap 5. More specifically, using one of the Bootswatch themes: Sketchy. Hopefully, that should be clear to anyone reading this. Unless Iāve gone and changed my mind again.
Partly, I was intrigued as to how simple it would be (spoilers: quite simple) and how quickly I could replace the existing site.
Iāve been discussing the possibility of replacing an existing Wordpress site elsewhere with a GitHub-hosted static site Ć la this one and wanted a feel for the effort involved (spoilers: not a lot.)
The Actual Hard Work
Having decided to implement the templates and now being aware of the specific files required, the first step was to move the old blog posts into this directory structure and modify as necessary.
Beyond modifying the necessary metadata in each postās header, there wasnāt actually much more required.
For instance, Hugo favours:
---
title: "š Hack the Shed"
date: 2019-06-19T20:19:51+01:00
description: "Drink all the booze; hack all the things."
tags: ["security", "owasp"]
categories: ["security"]
---
ā¦while the same file in Zola looks like:
+++
title = "š Hack the Shed"
date = 2019-06-19
description = "Drink all the booze; hack all the things."
[taxonomies]
tags = ["security", "owasp"]
categories = ["security"]
+++
The [taxonomies]
section is perhaps the biggest change: the tags
and categories
arenāt used by default in Zola and instead need to be configured. They are, however, arguably more versatile.
They need to be explicitly added in the configuration file, config.toml
:
taxonomies = [
{name = "tags", rss = true},
{name = "categories", rss = true},
]
As per Zolaās documentation, they can largely be any grouping needed but the previous taxonomies were left for now (if it aināt brokeā¦)
So we have:
- a handful of HTML templates files, using Bootstrap.
- the previous blog posts from the old site.
- errrrā¦profit?
Thatās actually it. Teething issues with Zola aside, the actual generation of the final site once the content was migrated and templates written (largely based on the numerous provided Bootstrap samples), was as simple as zola build
.
Now just to put that newly-generated static content somewhereā¦
Fork It
The previous mechanism for deploymentāand one Iād hoped to retain in this versionāwas via use of a Git submodule referencing an entirely separate, public GitHub repo. to which the static content can be pushed; the Zola code can therefore be isolated in a private repo. for tinkering.
Although Zola seemingly recommends submodules for themes it seems the developers are not fans for their use as part of the deployment process. The public
folder wherein the generated content is created by default, is nuked on each zola build
.
Arguably for familiarityās sake (and arguably to keep things progressing at a fair pace), I opted to create a fork and altered the cleanup stage of the site
sub-crate to:
- retain the root (i.e.
public
) folder. - ignore hidden files (i.e. the
.git
folder.) - delete all other folders therein as per existing behaviour.
Thankfully Zola already makes use of walkdir
so there were zero new dependencies. And it works.
And look at that, I even got a blog post out of it.