I was recently lucky enough to be enrolled by Forestry.io into writing a post for them!
The article is about building a Hugo JSON API with Hugo’s Output format. You can add it as a layer on top of your existing site or a simple stand-alone GET API.
Special thanks to Forestry’s Sebastian (@forestry.io) and @dwalkr for supporting me and shaping this article into an incredible read!
Yes, I just didn’t feel like adding a layer of .Scratch to the educational scope (primarly output format and templating). So I sticked with the basics on this one .
I’m putting together a custom data file for a list of categories and a list of tags.
The reason is to try and use them with Forestry.IO to make up for not being able to use a dropdown list when manually editing content. One of the few things I miss from WordPress.
I would like to be able to create separate files really rather than a single JSON file. No sure if that is possible but this is enough for now.
I’m also producing an index file that I will use for search.
{{ define "response" }}
[
{{ range $index, $e := .Data.Pages }}
{{ if $index }}, {{ end }}{{ .Render "item" }}
{{ end }}
]
{{ end }}
If I call http://localhost:1313/comune/accumoli/index.json I have a right output:
{
"data" : {
"name": "Accumoli (Lazio)"
}
}
If I call the list (http://localhost:1313/comune/index.json) the loop works (I have 6 items in “comune” section), but I do not have the render of the items:
Yes this is getting old and Hugo is moving fast! Try modifying the transformer file so the permalink is grabbed with this (.OutputFormats.Get "json").Permalink) rather than simply .Permalink.
I know I might be a little late to the party, but i was following your articles. And I just can’t make it work.
I’m stuck at customOutputs, seems like its not rendering the custom “players” json.
The common outputs in console: WARN 2019/09/29 12:29:31 found no layout file for “players” for “page”: You should create a template file which matches Hugo Layouts Lookup Rules for this combination.