This adds basic JSON rendering of term pages (e.g. contributors or projects; see config/_default/taxonomies.toml). To get the JSON, append "/index.json" to the regular page URL. The JSON contains: - unedited page params - the page permalink - a list of term-related page permalinks Using .Params as-is is a crude approach, as it would also include default hugo params (e.g. draft). An alternative would be to pick the params explicitly, but it is hard to define in a general way. The permalinks are to the default (i.e. html pages); probably there is a way to make them lead to json output; not sure which would be better. In the config file, the output format is defined per-Kind. It seems that the recommended way of generating output in a given format only for some pages of a kind (e.g. per-path) seems to be through cascades, https://discourse.gohugo.io/t/granular-output-configuration/50255/2
13 lines
469 B
JSON
13 lines
469 B
JSON
{{- /* collect permalinks to term-related pages */ -}}
|
|
{{- $relatedPermalinks := slice -}}
|
|
{{- range .Pages -}}
|
|
{{- $relatedPermalinks = $relatedPermalinks | append .Permalink -}}
|
|
{{- end -}}
|
|
{{/* make a dict of things which aren't in params */}}
|
|
{{- $otherThanParams := dict
|
|
"permalink" .Permalink
|
|
"content" (.Plain | emojify)
|
|
"related" $relatedPermalinks
|
|
-}}
|
|
{{/* merge those things with params, serve that */}}
|
|
{{ merge .Params $otherThanParams | jsonify }}
|