website/layouts/index.json

24 lines
854 B
JSON

{{ define "main" }}
{
{{ $postsDir := .Site.Params.Posts | default (slice "posts" "post") }}
{{ $postsList := where .Site.RegularPages "Section" "in" $postsDir }}
"page": "{{ .Paginator.PageNumber }}",
"next": {{ if .Paginator.HasNext }}
{{ .Paginator.Next.URL | absURL | jsonify }}
{{ else }}""{{ 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 }}