articles list json output

This commit is contained in:
Gabriele Musco 2021-04-13 09:15:13 +02:00
parent 6bdf871be6
commit 5f77073abd
No known key found for this signature in database
GPG Key ID: 8539FD3454380B83
1 changed files with 28 additions and 0 deletions

28
layouts/index.json Normal file
View File

@ -0,0 +1,28 @@
{
{{ $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 }},
"articles": [
{{ range $i, $e := (.Paginate $postsList).Pages }}
{{ 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 }},
"link": "{{ .Permalink }}"
{{ if .Site.Params.imageInArticlePreview }}
, "image": {{ if .Params.Image }}
{{ .Params.Image | jsonify }}{{ else }}""
{{ end }}
{{ end }}
}
{{ end }}
]
}