I’m working on a blog site for a writer who writes about wine. The blog posts refer to wines, grapes, wineries, and wine-producing regions, and the goal is for each post to link to a corresponding page that indexes the relevant posts. For example, if post A refers to the Tannat grape, then the word Tannat would be a link to ‘/grape/tannat’, and the page at that location would contain a link back to post A.
In some ways, this is a classic use-case for taxonomies: if I have a taxonomy for ‘grapes’, then my post just needs to contain:
grapes=[‘tannat’, ‘cabernet-sauvignon’]
etc. and a lot of the behavior I want will fall out automatically.
There are two isses, however. One is that some of my taxonomies are hierarchical: for example, the wine producing region of Mendoza is in Argentina, so I want a URL something like ‘/region/argentina/mendoza’. As far as I can tell, Hugo doesn’t support hierarchical taxonomies: all taxonomies are essentially ‘flat’.
The other is a DRY issue. I can use a custom shortcode to generate the link, i.e. my text might look like:
… this wine contains the {{< grape tannat >}}Tannat{{< /grape >}} grape …
but I’m forced to repeat myself: to get everything to work right, I need to add ‘tannat’ to the taxonomy in the frontmatter, and include the shortcode to generate the link in the text. What I’d really like is for something in the build to detect that ‘grape tannat’ shortcode, and automatically add ‘tannat’ to the list of taxonomy items for ‘grape’.
Is there a good way to do this in Hugo? I’m not averse to writing a pre-processor that scans the posts and extracts the shortcode data to build other content files if needed, but it would be nice if that could be tied into the Hugo build system so that it would run automatically, instead of having to be invoked as a separate step.
So my questions are:
- can Hugo support hierarchy in taxonomies?
- is there a way to run a pre-processor of some kind automatically as part of the build?
- can I avoid a pre-processor entirely, by somehow indexing the content of shortcodes?
Thank you in advance for any suggestions.