summaryrefslogtreecommitdiffstats
path: root/layouts/_default/list.json.json
diff options
context:
space:
mode:
authorSerghei Iakovlev <egrep@protonmail.ch>2022-05-22 20:01:48 +0200
committerSerghei Iakovlev <egrep@protonmail.ch>2022-05-22 20:01:48 +0200
commit36150b5f88b2e513c6791b62aaf5eb3401d1c8a2 (patch)
tree3371e3a1e40458297c3e190b537f3d476752212f /layouts/_default/list.json.json
parentaa0c41042a3a8bfa6834d0bedbd0b5bb7eece762 (diff)
downloadgohugo-theme-ed-36150b5f88b2e513c6791b62aaf5eb3401d1c8a2.tar.gz
Rework feeds to provide support for section
Diffstat (limited to 'layouts/_default/list.json.json')
-rw-r--r--layouts/_default/list.json.json43
1 files changed, 43 insertions, 0 deletions
diff --git a/layouts/_default/list.json.json b/layouts/_default/list.json.json
new file mode 100644
index 0000000..6151211
--- /dev/null
+++ b/layouts/_default/list.json.json
@@ -0,0 +1,43 @@
+{{- $pctx := . -}}
+{{- if .IsHome -}}{{ $pctx = .Site }}{{- end -}}
+
+{{- $pages := slice -}}
+{{- if $.IsHome -}}
+ {{- $pages = where $pctx.RegularPages.ByDate.Reverse "Type" "in" site.Params.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": {{ (printf "%s JSON Feed" site.Title) | 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.UTC.Format site.Params.dateFormatFeed | jsonify }}{{ if ne .Date .Lastmod }},
+ "date_modified" : {{ .Lastmod.UTC.Format site.Params.dateFormatFeed | jsonify }}{{ end }}
+ }
+ {{- end}}
+ ]
+}