This is something I've been battling with, so thought I'd share what I've learnt.
If you do not set taxonomies in your site configuration, these default values are inserted:
{
"taxonomies": {
"category": "categories",
"tag": "tags"
}
}
This seems to lead to a fairly common misconception that category and tag are hardwired into hugo, whereas they are merely suggested example names. There is a convention to use "singular": "plural"
. For my events listing sites, I've made my taxonomies:
{
"taxonomies": {
"venue": "venues",
"artist": "artists"
}
}
There can be any number of these, and the plural is akin to a section (ie it becomes a subdirectory in the URL). A cool thing I only recently discovered is if there is a content/<PLURAL>/<WHATEVER>/
directory with page resources, those resources can be accessed by the taxonomy templates.
Whatever plural name I picked now becomes a keyword for the frontmatter of pages which in my case are in content/events/<SOMENAME>/index.md
.
An example in my case would be
{
...
"artists": [
"Wonderboom",
"Chris Chameleon",
"Black Cat Bones",
"Pedro Barbosa",
"Koos Kombuis"
],
"venues": [
"Pta - Roodeplaat"
],
...
}
Hugo automagically turns the keywords in those lists into virtual subdirectories in the URL with lowercased, hyphenated names.
In my case, joeblog.co.za/events/example/ would create virtual pages
joeblog.co.za/artists/wonderboom (plus one for each other band in the list) along with joeblog.co.za/venues/pta-roodeplaat
Hugo's default is to treat "tag" pages as lists, whereas I want to treat them as leaf pages, and here found the corresponding names for their template files a bit confusing.
For joeblog.co.za/artists/
and joeblog.co.za/venues/
will happily default to layouts/_default/list.html
which is all I want. In my case I want the joeblog.co.za/artists/<WHATEVER>
page to be a single, but it too defaults to layouts/_default/list.html
.
I discovered one way to create the equivalent of a single.html
template, I need to call my templates artist.html
and venue.html
. Note it has to be singular, not plural.
A cool thing I only recently discovered is if there is a content/artists/wonderboom/
directory with page resources, those resources can be accessed by these templates.
If I want something other that the the default list template for the taxonomy pages, I found names like layouts/_default/artist.terms.html
worked. Again, it's important for your taxonomy's singular, not plural name to be used before .terms.html.
I find Hugo's template lookup order rules very confusing, so there are umpteen other options.