Display tags organized by section (or how to add a default taxonomy for each section)

Example structure

content/blog1
content/blog2

Each post in blog1 and blog2 contains tags. I’d like to print tags organized by each sections name. For example: display all the tags associated with blog1 and all the tags associated with blog2.

I believe this is archivable by setting a category or type taxonomy for every post under content/blog1 and content/blog2, so that content/blog1/post has category: blog in it’s front matter. But is there a way to do this without setting it up manually and adding category: blog1 to each post under content/blog1 and then printing the tags associated with the category taxonomy? I suppose I would have to write a separate, e.g. bash or python script to add this to all my posts.

I’m not sure, but maybe you are looking for Front Matter | Hugo.

1 Like

Thank you that solves one part of the puzzle.

Do you know how I can filter the tags so that I only print tags assosciated with blog1?

{{ range $tag, $value := $.Site.Taxonomies.tags }}
# only range over those tags that are also associated with `blog1` 

“associated” in this sense means getting the section, grabbing all the content in it, parsing their tags, and returning it as an array.

I’m sure you can do it, but Hugo doesn’t do it out of the box, you’ll need to do some clever templating for that. I’m not that clever. :slight_smile: