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

View File

@ -6,26 +6,18 @@
"next": {{ if .Paginator.HasNext }} "next": {{ if .Paginator.HasNext }}
{{ .Paginator.Next.URL | absURL | jsonify }} {{ .Paginator.Next.URL | absURL | jsonify }}
{{ else }}""{{ end }}, {{ else }}""{{ end }},
"articles": [ {{ $mscratch := newScratch }}
{{ range $i, $e := (.Paginate $postsList).Pages }} {{ $mscratch.Add "articles" slice }}
{{ if $i }}, {{ end }}{ {{ range (.Paginate $postsList).Pages }}
"ignore": {{ not (in $postsDir .Section) | jsonify }}, {{ $mscratch.Add "articles" (dict
"title": {{ .Title | jsonify }}, "ignore" (not (in $postsDir .Section))
"date": {{ .Date.Format "2006-01-02" | jsonify }}, "title" .Title
"tags": {{ if .Params.tags }} "date" (.Date.Format "2006-01-02")
{{ .Params.tags | jsonify }} "tags" (or .Params.tags slice)
{{ else }} "summary" .Summary
[] "link" .Permalink
{{ end }}, "image" (or .Params.Image "")) }}
"summary": {{ .Summary | jsonify }},
"link": "{{ .Permalink }}"
{{ if .Site.Params.imageInArticlePreview }}
, "image": {{ if .Params.Image }}
{{ .Params.Image | jsonify }}{{ else }}""
{{ end }}
{{ end }} {{ end }}
} "articles": {{ $mscratch.Get "articles" | jsonify }}
{{ end }}
]
} }
{{ end }} {{ end }}