Is it possible to configure taxonomies to work with non-array values in frontmatter?
For example, imagine the post:
---
year: 2001
categories: ["cata", "catb"]
---
post body
It is easy to configure taxonomies on the categories element of the frontmatter.
config.toml
[taxonomies]
category = "categories"
However what if we also want a taxonomy on the year member of the frontmatter. In the context of this site it doesn’t make sense for the post to have more than one year.
If I change my config.toml to
[taxonomies]
category = "categories"
year = "years"
no pages are listed in the taxonomy when I have this in my template:
Have you tried year: ["2001"]? (That’s just a guess).
However, is there any specific use case for this? I think, you can already sort posts by date in Hugo and (I’m not sure), but, there must be some other way that could be used to group posts by year.
Edit: I just noticed, you’re using year in frontmatter, but, in config, you’ve set the word as years. Possibly another cause of an error.
I could change the year field to an array, but would prefer not to because I am using Netlify’s cms and it doesn’t make sense for a post to have multiple years.
I was hoping there would be a configuration setting or option to allow a single year to be used from the frontmatter.
This would be a hacky way and you (and even myself), won’t like it, but, can use used as a last resort. You could create a separate frontmatter field to be used by netlify CMS and the taxonomy.
If someone more knowledgeable answers with a better solution you’re good to go, but, if you want something quick, you can give that a try.