diff --git a/layouts/_default/search.json b/layouts/_default/search.json index 7dae89a..22ce283 100644 --- a/layouts/_default/search.json +++ b/layouts/_default/search.json @@ -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 }} diff --git a/layouts/index.json b/layouts/index.json index 7d8529c..bfa8dde 100644 --- a/layouts/index.json +++ b/layouts/index.json @@ -6,26 +6,18 @@ "next": {{ if .Paginator.HasNext }} {{ .Paginator.Next.URL | absURL | jsonify }} {{ else }}""{{ end }}, - "articles": [ - {{ range $i, $e := (.Paginate $postsList).Pages }} - {{ if $i }}, {{ end }}{ - "ignore": {{ not (in $postsDir .Section) | jsonify }}, - "title": {{ .Title | jsonify }}, - "date": {{ .Date.Format "2006-01-02" | jsonify }}, - "tags": {{ if .Params.tags }} - {{ .Params.tags | jsonify }} - {{ else }} - [] - {{ end }}, - "summary": {{ .Summary | 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 (.Paginate $postsList).Pages }} + {{ $mscratch.Add "articles" (dict + "ignore" (not (in $postsDir .Section)) + "title" .Title + "date" (.Date.Format "2006-01-02") + "tags" (or .Params.tags slice) + "summary" .Summary + "link" .Permalink + "image" (or .Params.Image "")) }} + {{ end }} + "articles": {{ $mscratch.Get "articles" | jsonify }} } {{ end }}