HUGO

Single view of information on data/articles.json

Is there any way to have a permalink that shows information from a single entry from a JSON file?

I’m aware this isn’t the usual way of publishing posts or pages, but I am trying to use Hugo for an edge case. It’s a website that aggregates daily searches in a number of verified sources and links back to them.

The information comes from an API and the single.html will show a summary and some metadata from the search.

Is this even possible ?

Option A - Pages from Data

Perhaps the cleanest approach is to automatically create a page for each entry in the JSON file. Hugo can’t do that yet. See:

Option B - List Everything, Display None/One

Next you could look at creating a monolithic page with all of the entries, each encapsulated by a parent element with a unique id and CSS display property set to none. Then include the unique id in the URL (e.g., https://example.com/results?id=123), and use some JS to toggle the CSS display property of the related element.

Option C - gomplate

See https://discourse.gohugo.io/t/using-gomplate-to-generate-pages-from-data-sources/27160

n.b. I have no experience with this approach.

Option D - External Script

Something like https://discourse.gohugo.io/t/split-a-json-array-into-markdown-files/30919.

n.b. I have no experience with this approach.

1 Like

Thank you for the in-depth answer @jmooring :slightly_smiling_face:

Option B feels like it’s easier for me to achieve with what I know of JS but the JSON file will eventually grow and when that time comes I will move on to Gomplate. Wouldn’t like to have the user download 1 or 10Mb of JSON just to view one single entry.