Use tags as taxonomy AND content

Hi folks,

What I’m trying to do

I’m creating a blog, where each post can have multiple tags. Each of these tags will have a matching page containing:

  • The name of the tag (title)
  • A short description of the tag
  • A list of all posts using this tag

What I got so far

Structure

├─ content
|   ├─ posts
|   |  └─ hello-world.md
|   └─ tags
|      ├─ cooking.md
|      └─ climbing.md
├─ layouts
|   └─ tags
|      ├─ taxonomy.md
|      └─ list.md

hellow-world.md

+++
tags = ["Cooking"]
+++

cooking.md

+++
title = "Cooking"
description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam rutrum lectus libero, sit amet aliquam odio lobortis non. Morbi egestas at augue eu aliquet. " 
+++

website/tags/

When looping though the .Pages object, I got both the cooking content entry, and the cooking tag from the post:

Page(/tags/cooking.md) 
Page(/tags/cooking) Cooking

website/tags/cooking

On this page, I don’t have access to the .Description because this is not the tag content entry, but the tag entry from the post.


There is some default Hugo behavior here, and I’m not sure of how to handle it.
Is is doable?

I think what you need to do is create these files

/tags/cooking/_index.md
/tags/climbing/_index.md

In the content of the _index.md files is what you’ve currently got in your named Markdown front matter.

See https://gohugo.io/content-management/taxonomies/#add-custom-metadata-to-a-taxonomy-term

1 Like

It’s working, thanks!

But this blog will be managed via Forestry (by a non technical person), and it will create /content/tags/name.md files… There is no way to keep the cooking.md structure?

With Forestry, might be better ask in their Slack channel. You could also look at NetlifyCMS, though I doubt it’s any better at solving this problem,.

I do this type of thing on my Tags page (https://www.ii.com/meta/tags/) and have had to create a (for example) /tags/cooking/_index.md for each tag that has a description. I think the problem is that each tag page, e.g. Cooking, is a list page and in Hugo you specify content for a list page with a file named _index.md.[*] I’ve wondered if there is a way to specify all tag descriptions in a data file, e.g.:

cooking: cooking description
climbing: climbing description
tag: tag description

and avoid creating all those tag _index.md files. Would that be helpful to you? If so, maybe someone will help us figure out how to do that. I think it would not be hard, but I have not yet used Hugo data files.

[*] Or _index.mmark, _index.adoc, etc.

Thanks for your answers. I will stick to the /_index.md solution for now. Forestry is planning to add the support for this structure in their roadmap.