Hugo Taxonomies are great but just like everything else in life, they currently have one major flaw (at least for me).
When the user needs to pass content to a taxonomy list page she must use the following path /taxonomy-name/taxonomy-term-_index.md
and repeat this per taxonomy term.
Obviously that is a lot of folders to maintain not only when organizing a Hugo Site but especially when the content of taxonomy list pages needs to be updated.
There has been some discussion about overriding this limitation during the past few days with the introduction of new and a kind of hacky technique that was developed by @guayom , a Github Issue by yours truly (that ended up in a misunderstanding) and a blueprint for the Hugo taxonomy generator (that does not really address the folder problem) by @rdwatters
This is my take on this issue. It works 100%. It’s fast. And I’m happy.
It is a very simple technique that utilizes front matter parameters (in this example just plain old tags) and Hugo Sections. And I can’t see this workaround breaking in the future unless of course Hugo changes beyond recognition. Or of course I’m missing something. Anyway enough talk.
Step 1
Assign tags to your posts as you usually do like:
tags = [ "handbags", "versace" ]
Step 2
Under /content/
create a folder called brands
Within this folder create .md
files for as many taxonomy terms as you need.
In your front matter include the title
and description
parameters you want to have rendered on your taxonomy list page, as well as a very important parameter that needs to contain the exact same tag you assigned to your posts in Step 1.
You can call this new parameter anything you want in my example I’ve called it folksy
(from Folksonomy) (thanks for the link @rdwatters ) :
+++ title = "Versace AW 2017" description = "La Nuova Collezione di Borse Versace" folksy = "versace" +++
Step 3
Now in the template for our custom brands
taxonomy (that is really just a plain old Hugo Section) located at /layouts/brands/single.html
place the following:
{{ $tag:= .Params.Folksy }} {{ range ($.Site.GetPage "taxonomy" "tags" $tag).Pages }} HTML HERE {{ end }}
First I assigned a variable for the folksy
parameter
{{ $tag:= .Params.Folksy }}
And then I used range
with a nested .GetPage
function to fetch the posts I need while using the above variable to fetch the tag dynamically (sneaky ain’t it?).
{{ range ($.Site.GetPage "taxonomy" "tags" $tag).Pages }}
And that’s it!
Now you have just one taxonomy folder with the full taxonomy terms list pages and you can update them as often you need without clicking your life away.
TIP: You can also use this technique to render a taxonomy terms menu anywhere you need on your site and pass meta descriptions and other attributes to the <head>
of your Hugo Project.
I would like to thank @spf13 @bep and all the other developers for their time and hard work in making the greatest static site generator that even me a non-Dev Art Director can understand.
Special thanks to @moorereason @rdwatters @jura @budparr and all the others who have helped me in this forum while I was here.
Keep Hugo-ing!
I’m out of here for now. But I’ll be around…