website/layouts/index.json

39 lines
1.6 KiB
JSON
Raw Normal View History

{{ define "main" }}
2021-04-13 02:15:13 -05:00
{
{{ $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 }}
2021-04-13 15:33:49 -05:00
{{ $mscratch := newScratch }}
{{ $mscratch.Add "articles" slice }}
{{ range (.Paginate $postsList).Pages }}
{{ $image := "" }}
{{ if .Params.Image }}
{{ if or (hasPrefix .Params.Image "/") (hasPrefix .Params.Image "http://") (hasPrefix .Params.Image "https://") }}
{{ $image = .Params.Image }}
{{ else }}
2022-10-25 00:07:20 -05:00
{{ $image = print .Permalink "/" .Params.Image }}
{{ end }}
{{ end }}
2021-04-13 15:33:49 -05:00
{{ $mscratch.Add "articles" (dict
"title" .Title
"date" (.Date.Format "2006-01-02")
2021-06-16 04:08:07 -05:00
"tags" (sort (or .Params.tags slice))
"summary" (or .Params.description .Summary)
2021-04-13 15:33:49 -05:00
"link" .Permalink
2022-10-24 01:16:12 -05:00
"image" $image
"imageAlt" (or .Params.Alt "")) }}
2021-04-13 15:33:49 -05:00
{{ 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 }}
2021-04-13 02:15:13 -05:00
}
{{ end }}