summaryrefslogtreecommitdiffstats
path: root/layouts
diff options
context:
space:
mode:
authorSerghei Iakovlev <egrep@protonmail.ch>2022-07-03 23:53:41 +0200
committerSerghei Iakovlev <egrep@protonmail.ch>2022-07-04 09:09:04 +0200
commitfce52fd0cba815e564b8fbd996e6766337852274 (patch)
tree9ccc3de6cae67e9043aeb8b910204c5946ee9819 /layouts
parentd9d692148f7e8cffe04128ba3026f3b6a70dc50b (diff)
downloadgohugo-theme-ed-fce52fd0cba815e564b8fbd996e6766337852274.tar.gz
Provide template to render pure JSON
Diffstat (limited to 'layouts')
-rw-r--r--layouts/_default/list.json29
-rw-r--r--layouts/_default/list.jsonfeed.json (renamed from layouts/_default/list.json.json)0
2 files changed, 29 insertions, 0 deletions
diff --git a/layouts/_default/list.json b/layouts/_default/list.json
new file mode 100644
index 0000000..5742bb3
--- /dev/null
+++ b/layouts/_default/list.json
@@ -0,0 +1,29 @@
+{{- $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 -}}
+
+{{- $.Scratch.Add "pagesIndex" slice -}}
+
+{{- range $index, $page := $pages -}}
+ {{- if gt (len $page.Content) 0 -}}
+ {{- $pageData := (dict
+ "title" $page.Title
+ "href" $page.Permalink
+ "tags" (delimit ($page.Params.tags | default slice) " ; ")
+ "categories" (delimit ($page.Params.categories | default slice) " ; ")
+ "content" $page.Plain
+ ) -}}
+ {{- $.Scratch.Add "pagesIndex" $pageData -}}
+ {{- end -}}
+{{- end -}}
+
+{{- $.Scratch.Get "pagesIndex" | jsonify -}}
diff --git a/layouts/_default/list.json.json b/layouts/_default/list.jsonfeed.json
index f6b89cc..f6b89cc 100644
--- a/layouts/_default/list.json.json
+++ b/layouts/_default/list.jsonfeed.json