Hugo Taxonomies

Tegami Bachi screenshot

You might have read Ruben’s so far modest writings about Hugo, and it’s my turn to jump on the bandwagon about what I’ve been doing on this blog. Yesterday, Ruben helped me move my blog over from Jekyll to Hugo and it was a very smooth one as far as transitions go, though of course a lot to wrap your head around when coming into something new.

Thanks to this process, Ruben’s months figuring all this out meant that I was up and running within an evening, and themed up within another few hours. It was a chance to work with some clean code this time, rather than the spaghetti mess that my Jekyll themes had become (from the backend). But today I want to look at Taxonomies.


It seems that by default, Hugo creates the tags and categories taxonomies by default, so they don’t need to be defined, but if you want to create archive pages of any other descriptions, you need to first define a taxonomy.

To be honest, reading all of the documentation on Taxonomies on the Hugo website, all of the pages were unintelligible to me, but I managed to ascertain from the ‘Usage’ page that I basically had to define it in the .yaml or .toml config in the format of singular key: “plural value” in the .yaml.

    year: "years"
    archive: "archives"

This helped a bit too, to put it in perspective. Generally I can see Taxonomies are good for creating series of posts, but I’ve just used for my purposes.

Then it was a tedious simple matter of adding these fields to the front matter of all your posts, as we already do with categories and tags. I added a two new lines to the front matter of each post i.e. archives: and years:.

From the date and a Perl script that Ruben had helped me with earlier, I was able to take the year from the filename of the post (formatted in format) and inserted archives: archive as another line in each post.

layout: post
archives: "archive"
title: "Hugo Taxonomies"
slug: "hugo-taxonomies"
date: "2015-05-10T14:10:23+11:00"
years: "2015"
 - technology
 - hugo
 - taxonomies

This is a wonderfully disgusting hack based on repetitive information that, were I not adamant of having specific kinds of archive pages, I wouldn’t bother with. However it has created the archive pages that I wanted so I’m not complaining.

The hardest part in all of this was trying to find where the pages were, to be honest. As it turns out, my archive page was in /archives/archive/. If there’s a better way of doing this, I would like to know, but that’s all I could work out after using Hugo for a couple of hours. It shall suffice for now!