summaryrefslogtreecommitdiffstats
path: root/layouts/index.json
diff options
context:
space:
mode:
authorSerghei Iakovlev <egrep@protonmail.ch>2022-07-11 09:44:01 +0200
committerSerghei Iakovlev <egrep@protonmail.ch>2022-07-11 09:44:01 +0200
commit0e5fe09b09bf9491732748520e6ad37b74453488 (patch)
tree10e6a9b070626353efcdba9f9bc69b3007d8a57d /layouts/index.json
parent477e47f4eda5344b799839d0d645d125c903b099 (diff)
downloadgohugo-theme-ed-0e5fe09b09bf9491732748520e6ad37b74453488.tar.gz
Rework site search to pass config params
Diffstat (limited to 'layouts/index.json')
-rw-r--r--layouts/index.json47
1 files changed, 36 insertions, 11 deletions
diff --git a/layouts/index.json b/layouts/index.json
index 05d731f..538cfcc 100644
--- a/layouts/index.json
+++ b/layouts/index.json
@@ -1,3 +1,4 @@
+{{- /* Generate the search index. */ -}}
{{- $pages := slice -}}
{{- $mainSections := site.Params.mainSections | default (slice "posts") }}
@@ -7,19 +8,43 @@
{{- $.Scratch.Add "urlsAdded" slice -}}
{{- range $index, $page := $pages -}}
- {{- if gt (len $page.Content) 0 -}}
- {{- if not (in ($.Scratch.Get "urlsAdded") $page.Permalink) -}}
- {{- $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 -}}
- {{- $.Scratch.Add "urlsAdded" $page.Permalink -}}
+ {{- /* Do not index drafts or private pages. */ -}}
+ {{- if and (not .Draft) (not .Params.private) | and (ne .Params.searchable false) -}}
+
+ {{- /* Do not index pages w/o content. */ -}}
+ {{- if gt (len $page.Content) 0 -}}
+
+ {{- /* Add page to index. */ -}}
+ {{- if not (in ($.Scratch.Get "urlsAdded") $page.Permalink) -}}
+
+ {{/* Exclude virtual pages which aren't backed by a file */}}
+ {{ if .File }}
+ {{- $pageData := (dict
+ "objectID" $page.File.UniqueID
+ "date" $page.Date.UTC.Unix
+ "publishDate" $page.PublishDate
+ "lastmod" $page.Lastmod.UTC.Unix
+ "expiryDate" $page.ExpiryDate.UTC.Unix
+ "lang" $page.Lang
+ "title" $page.Title
+ "href" $page.Permalink
+ "kind" $page.Kind
+ "type" $page.Type
+ "section" $page.Section
+ "tags" (delimit ($page.Params.tags | default slice) " ; ")
+ "categories" (delimit ($page.Params.categories | default slice) " ; ")
+ "content" $page.Plain
+ ) -}}
+ {{- $.Scratch.Add "pagesIndex" $pageData -}}
+ {{- $.Scratch.Add "urlsAdded" $page.Permalink -}}
+ {{- end -}}
+
+ {{- end -}}
+
{{- end -}}
+
{{- end -}}
+
{{- end -}}
{{- $.Scratch.Get "pagesIndex" | jsonify -}}