I have a bunch of local data files named data/news/2024.json
, data/news/2023.json
etc., each one containing news items that I intend to use to build news pages on a site.
Historically, Hugo has not (AFAIK) provided a way to build pages from data files (a feature available in some other SSGs). In fact, I think that somewhere in the docs there was a stern warning saying “That’s not what it’s for; don’t do this”, or words to that effect.
In other words, there isn’t a way to take my data/news/2024.json
and get a news/2024.md
from it. I need to create a stub news/2024.md
file and then use a layout template to pull in the data from data/news/2024.json
.
With the new content adapters, however, it looks as if I can create a _content.gotmpl
file in the appropriate place and then iterate over the local data, e.g.
{{ range .Site.Data.news }}
...
{{ $page := ... }}
{{ $.AddPage $page }}
{{ end }}
This seems to work pretty well, and means that I don’t need to repeat myself: I just put the data files in the data/news
directory and my pages are generated for me.
My question is: is this a legitimate and safe use of content adapters? It seems reasonable to me, but as it’s not explicitly called out as a possibility in the docs, I wanted to be sure that this wasn’t abusing the feature in a way that might cause it to stop working in some future release.