Skip to content

Instantly share code, notes, and snippets.

@takakd
Last active November 6, 2017 17:23
Show Gist options
  • Save takakd/373f5d835a1d5d47e0bb136d02612bc6 to your computer and use it in GitHub Desktop.
Save takakd/373f5d835a1d5d47e0bb136d02612bc6 to your computer and use it in GitHub Desktop.
sample-hugo-json
{
"posts": [
{{ $list := .Data.Pages -}}
{{ $len := (len $list) -}}
{{ if lt 0 $len -}}
{{ range first 1 $list -}}
{
"id" : {{ .Date.Format "20060102150405" | jsonify }},
"date" : {{ if .Date }}{{ .Date.Format "2006.01.02" | jsonify }}{{else}}""{{end}},
"title" : {{ .Title | jsonify }},
"summary" : {{ .Summary | jsonify }},
"body" : {{ .Content | jsonify }},
"tags" : {{ if .Params.tags }}{{ .Params.tags | jsonify }}{{ else }}[]{{ end }},
"some-ex-param" : {{ if .Params.someexparam }}{{ .Params.someexparam | jsonify }}{{ else }}false{{ end }}
}
{{- end -}}
{{- end -}}
{{- if lt 1 $len -}}
{{- range after 1 $list -}}
,{
"id" : {{ .Date.Format "20060102150405" | jsonify }},
"date" : {{ if .Date }}{{ .Date.Format "2006.01.02" | jsonify }}{{else}}""{{end}},
"title" : {{ .Title | jsonify }},
"summary" : {{ .Summary | jsonify }},
"body" : {{ .Content | jsonify }},
"tags" : {{ if .Params.tags }}{{ .Params.tags | jsonify }}{{ else }}[]{{ end }},
"some-ex-param" : {{ if .Params.sameexparam }}{{ .Params.sameexparam | jsonify }}{{ else }}false{{ end }}
}
{{- end -}}
{{- end }}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment