Zdoc has an “Updates” section, but the articles inside it were created by hand. Since I’m lazy (laziest person in the world right here) and I don’t like to do things by hand when they can be automated, I tried to get some way of producing a Site Index without handcrafting each page.
In WordPress and other dynamic platforms it’s dead easy, but on a static site like Hugo, all the proposed solutions involved plugins, NPM, Node.js, things I did not want to mess with (for now).
Fortunately, there’s a way of faking this functionality using an internal Hugo system, Taxonomies. Thankfully, I do not use Taxonomies for anything else, but I don’t know at the moment if doing this will prevent other uses for them.
I added this to config.toml
|
|
This automatically adds pages site
/updates/year
e pages site
/updates/year
/month
, filled with the :slug
of all pages that have these values in the variables year:
and month:
that we can now start placing on the frontmatter of each page, like this:
|
|
To generate these fields automatically when you create an article or post with hugo new
, I added the following to the frontmatter of the archetypes archetypes/blog/post.md
and archetypes/default.md
:
year: ["{{ now.Format "2006" }}"]
month: ["{{ now.Format "2006/01" }}"]
And to prevent these pages from being formatted like they were part of the Blog section (which is the default configuration for Taxonomies), I changed the following in layouts/_default/taxonomy.html
|
|
layouts/partials/header/custom-header.html
is empty; if you want something else, you can edit it or make a new one. Just remember that as it is, it will be applied to all Taxonomies.Then all I had to do was make static links in the
content/<lang>/updates/_index.md
page to the auto-generated pages:
|
|
Yes, I still have to create these links by hand, but the pages behind the links are created without forcing me to put each post there one by one.
That’s progress!
Sources:
https://discourse.gohugo.io/t/how-to-generate-chronological-blog-archives-in-hugo/13491/5
https://discourse.gohugo.io/t/strugling-with-chronological-blog-archive/31963/2
https://gohugo.io/templates/lists/