topics: hugo (tidbits)

Disabling A Single Hugo Taxonomy List Page

Hugo provides a flexible Taxonomy system that is configured by default with “tag” and “category” taxonomies.

The Taxonomy of a piece of content can be configured in its front matter.

For example content/test.md:

---
tags: [tag1]
categories: [cat1]
---

Observing the automatically generated sitemap.xml, we see Taxonomy list pages for /categories/ and /tags/. We can also see a URL generated for /catagories/cat1/ and /tags/tag1/:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="...">
<url><loc>http://localhost:1313/test/</loc></url>
<url><loc>http://localhost:1313/categories/cat1/</loc></url>
<url><loc>http://localhost:1313/categories/</loc></url>
<url><loc>http://localhost:1313/</loc></url>
<url><loc>http://localhost:1313/tags/tag1/</loc></url>
<url><loc>http://localhost:8080/tags/</loc></url>
</urlset>

DisableKinds Configuration

Hugo provides a disableKinds directive in the main configuration file, config.toml. This directive allows “taxonomy”, “taxonomyTerm” and others to be disabled globally. With disableKinds = ["taxonomy", "taxonomyTerm"] added to config.toml we can see from the generated sitemap what has happened:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="...">
<url><loc>http://localhost:8080/test/</loc></url>
<url><loc>http://localhost:8080/</loc></url>
</urlset>

URLs /categories/, /categories/cat1/, /tags/, /tags/tag1/ are no longer generated.

To disable just the /categories/ and /tags/ URLs, we can amend the disableKinds configuration to:

disableKinds = ["taxonomyTerm"]

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="...">
<url><loc>http://localhost:8080/test/</loc></url>
<url><loc>http://localhost:8080/categories/cat1/</loc></url>
<url><loc>http://localhost:8080/</loc></url>
<url><loc>http://localhost:8080/tags/tag1/</loc></url>

</urlset>

Is it possible to disable a single Hugo Taxonomy list page without disabling all of them?

Hugo allows for the enrichment of members of its Taxonomy system via front-matter, as with other content.

To add additional meta-data to the tag Taxonomy we can create a file with path content/tags/_index.md.

---
_build:
    render: false
    list: never
---

These options are documented in the Build Options section of the Hugo documentation.

With the disableKinds configuration added previously removed we see that just the /tags/ URL is no longer generated:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="...">
<url><loc>http://localhost:8080/test/</loc></url>
<url><loc>http://localhost:8080/categories/cat1/</loc></url>
<url><loc>http://localhost:8080/categories/</loc></url>
<url><loc>http://localhost:8080/</loc></url>
<url><loc>http://localhost:8080/tags/tag1/</loc></url>
</urlset>