I want to create a single taxonomy that is essentially the union of a page’s “parent directory name” and keywords (specified in front matter, if any). In other words: I want the directory to act as an implicit keyword.
Example with two posts (under “content/” root):
- “posts/hugo/about-hugo.md” (with no keywords specified in front matter)
- “posts/debugging/debug-hugo.md” (with “keywords: [hugo]” in front matter)
In this case, I want both posts to be in a taxonomy under the term “hugo” (the first due to it being in the “hugo” directory, and the second because it’s explicitly marked with “hugo” as a keyword in front matter).
Let me know if it’s not clear what I’m trying to achieve!
Is there any way to do this in Hugo?
The taxonomy docs make me think that taxonomy terms can only be added using front matter. If that’s the case, is there anyway to programmatically recreate taxonomy-like behavior using variables and functions?
I’ve been playing around with the slices/
append, and it looks like I might be able to create an array and/or map that contains taxonomy-like information (not 100% sure this is possible), and maybe I can store that in
.Scratch for use across my templates (also note 100% sure this would work), but I’m unsure how to make it generate taxonomy term pages (in fact, I think this is not possible, based on the Build pages from data source open issue).
So from what I’ve read thus far, I suspect this is not possible, but I’d love to be proven wrong
Edit to add: Ideally, I wouldn’t have to clutter up my content with manually-generated files. I say this because I thought it might have been possible to set an explicit keyword in “_index.md” of each directory and cascade it down if necessary. Note: I haven’t gotten that approach to work (edit: because the “keywords” property seems to get overwritten entirely instead of merged), so it’s possible that’s a dead end anyway.