website/layouts/index.json

30 lines
1.2 KiB
JSON

{{ define "main" }}
{
{{ $postsDir := .Site.Params.Posts | default (slice "posts" "post") }}
{{ $allPostsList := where .Site.RegularPages "Section" "in" $postsDir }}
{{ $featuredPostsList := slice }}
{{ $postsList := $allPostsList }}
{{ if .Site.Params.enableFeatured | default false }}
{{ $featuredPostsList = where $allPostsList "Params.featured" true }}
{{ $postsList = union (where $allPostsList "Params.featured" false) (where $allPostsList "Params.featured" nil) }}
{{ end }}
{{ $mscratch := newScratch }}
{{ $mscratch.Add "articles" slice }}
{{ range (.Paginate $postsList).Pages }}
{{ $mscratch.Add "articles" (dict
"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 }},
"test": "{{range $postsList}}{{.Title}} {{end}}",
"page": "{{ .Paginator.PageNumber }}",
"next": {{ if .Paginator.HasNext }}
{{ .Paginator.Next.URL | absURL | jsonify }}
{{ else }}""{{ end }}
}
{{ end }}