greatly simplified json generation

This commit is contained in:
Gabriele Musco 2021-04-13 22:33:49 +02:00
parent 6f18465f88
commit 4239ea5347
No known key found for this signature in database
GPG key ID: 8539FD3454380B83
2 changed files with 26 additions and 43 deletions

View file

@ -1,26 +1,17 @@
{{ define "main" }}
{
"pages": [
{{ range $i, $e := .Site.RegularPages }}
{{ if $i }},{{ end }}
{
"title": {{ .Title | jsonify }},
"date": {{ .Date.Format "2006-01-02" | jsonify }},
"tags": {{ if .Params.tags }}
{{ .Params.tags | jsonify }}
{{ else }}
[]
{{ end }},
"summary": {{ .Summary | jsonify }},
"text": {{ lower .Plain | jsonify }},
"link": "{{ .Permalink }}"
{{ if .Site.Params.imageInArticlePreview }}
, "image": {{ if .Params.Image }}
{{ .Params.Image | jsonify }}{{ else }}""
{{ end }}
{{ end }}
}
{{ end }}
]
{{ $mscratch := newScratch }}
{{ $mscratch.Add "articles" slice }}
{{ range .Site.RegularPages }}
{{ $mscratch.Add "articles" (dict
"title" .Title
"date" (.Date.Format "2006-01-02")
"tags" (or .Params.tags slice)
"summary" .Summary
"text" (lower .Plain)
"link" .Permalink
"image" (or .Params.Image "")) }}
{{ end }}
"pages": {{ $mscratch.Get "articles" | jsonify }}
}
{{ end }}