Skip to content

Instantly share code, notes, and snippets.

@voidfiles
Created May 19, 2017 22:08
Show Gist options
  • Save voidfiles/302e8d690a5ef4990e371ce70bca3240 to your computer and use it in GitHub Desktop.
Save voidfiles/302e8d690a5ef4990e371ce70bca3240 to your computer and use it in GitHub Desktop.
Hugo JSON Feed Template add to layouts/index.json
{
"version": "https://jsonfeed.org/version/1",
"title": {{ .Site.Title | jsonify }},
"home_page_url": {{ .Permalink | jsonify }},
{{ with .OutputFormats.Get "json" -}}
"feed_url": {{ .Permalink | jsonify }},
{{- end }}
{{ if (.Site.Params.author) or (.Site.Params.author_url) -}}
"author": {
{{ if .Site.Params.author -}}
"name": {{ .Site.Params.author | jsonify }},
{{- end }}
{{ if .Site.Params.author_url -}}
"url": {{ .Site.Params.author_url | jsonify }}
{{- end }}
},
{{- end }}
{{ if .Data.Pages }}
"items": [
{{ range $index, $element := first 10 .Data.Pages }}
{{if $index }},{{end}} {
"title": {{ $element.Title | jsonify }},
"id": {{ $element.Permalink | jsonify }},
"url": {{ $element.Permalink | jsonify }},
"content_html": {{ $element.Content | jsonify }},
"date_published": {{ $element.Date.Format "2006-02-01T15:04:05-0700" | jsonify }}
}
{{ end }}
]
{{ end }}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment