diff options
| author | Serghei Iakovlev <egrep@protonmail.ch> | 2022-07-03 23:53:41 +0200 |
|---|---|---|
| committer | Serghei Iakovlev <egrep@protonmail.ch> | 2022-07-04 09:09:04 +0200 |
| commit | fce52fd0cba815e564b8fbd996e6766337852274 (patch) | |
| tree | 9ccc3de6cae67e9043aeb8b910204c5946ee9819 /layouts/_default/list.jsonfeed.json | |
| parent | d9d692148f7e8cffe04128ba3026f3b6a70dc50b (diff) | |
| download | gohugo-theme-ed-fce52fd0cba815e564b8fbd996e6766337852274.tar.gz | |
Provide template to render pure JSON
Diffstat (limited to 'layouts/_default/list.jsonfeed.json')
| -rw-r--r-- | layouts/_default/list.jsonfeed.json | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/layouts/_default/list.jsonfeed.json b/layouts/_default/list.jsonfeed.json new file mode 100644 index 0000000..f6b89cc --- /dev/null +++ b/layouts/_default/list.jsonfeed.json @@ -0,0 +1,44 @@ +{{- $pctx := . -}} +{{- if .IsHome -}}{{ $pctx = .Site }}{{- end -}} + +{{- $pages := slice -}} +{{- if $.IsHome -}} + {{- $mainSections := site.Params.mainSections | default (slice "posts") }} + {{- $pages = where $pctx.RegularPages.ByDate.Reverse "Type" "in" $mainSections -}} +{{- else if $.IsSection -}} + {{- $pages = $pctx.RegularPages.ByDate.Reverse -}} +{{- else -}} + {{- $pages = $pctx.Pages -}} +{{- end -}} + +{{- $limit := site.Params.feedSize | default 25 -}} +{{- $pages = $pages | first $limit -}} + +{ + "version": "https://jsonfeed.org/version/1.1", + "title": {{ (partial "title.html" .) | htmlUnescape | jsonify }}, + "home_page_url": {{ printf "%s?utm_source=json_feed" site.BaseURL | absURL | jsonify }}, + {{ with .OutputFormats.Get "JSON" }}"feed_url": {{ .Permalink | absURL | jsonify }},{{ end }} + {{ with site.Params.description}}"description": {{ site.Params.description | jsonify }},{{ end }} + {{- $logo := resources.Get (site.Params.assets.logo | default "/img/open-graph-logo.png") }}{{ $logo = $logo.Resize "96x96" }} + "icon": {{ $logo.Permalink | jsonify }}, + "favicon": {{ $logo.Permalink | jsonify }}, + {{ with site.Author.name }}"authors": [ + { + "name": {{ . | jsonify }}{{ with site.Author.twitter }}, + "url": {{ (printf "https://twitter.com/%s" . ) | jsonify }}{{ end }} + } + ],{{ end }} + {{ with site.LanguageCode }}"language" : "{{ . }}",{{ end }}{{ $feedsize := site.Params.feedSize | default 25 }} + "items": [{{ range $i, $ := $pages }}{{ if $i }},{{ end }} + { + "id": {{ $uuid := sha1 (.Permalink | absURL)}}"{{substr $uuid 0 8}}-{{substr $uuid 8 4}}-5{{substr $uuid 13 3}}-{{substr $uuid 16 1}}9{{substr $uuid 17 2}}-{{substr $uuid 21 12}}", + "url": {{ printf "%s?utm_source=json_feed" .Permalink | jsonify }}, + "title": {{ .Title | plainify | chomp | jsonify }}, + "summary": {{ .Summary | plainify | chomp | jsonify }}, + "date_published": {{ .PublishDate.Format "2006-01-02T15:04:05Z07:00" | jsonify }}{{ if ne .Date .Lastmod }}, + "date_modified" : {{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" | jsonify }}{{ end }} + } + {{- end }} + ] +} |
