blob: a71d1e659f88ee3a9d19286e537ff45b59e00e36 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
{{- /* Generate the search index. */ -}}
{{- $pages := slice -}}
{{- $mainSections := site.Params.mainSections | default (slice "posts") }}
{{- $pages = where site.RegularPages.ByDate.Reverse "Type" "in" $mainSections -}}
{{- $.Scratch.Add "pagesIndex" slice -}}
{{- $.Scratch.Add "urlsAdded" slice -}}
{{- range $index, $page := $pages -}}
{{- /* 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
"publishDate" $page.PublishDate
"date" $page.Date.UTC.Unix
"lastmod" $page.Lastmod.UTC.Unix
"lang" ($page.Params.lang | default $page.Lang)
"title" $page.Title
"href" $page.Permalink
"kind" $page.Kind
"type" $page.Type
"section" $page.Section
"content" $page.Plain
"categories" ($page.Params.categories | default slice)
"tags" ($page.Params.tags | default slice)
) -}}
{{- $.Scratch.Add "pagesIndex" $pageData -}}
{{- $.Scratch.Add "urlsAdded" $page.Permalink -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $.Scratch.Get "pagesIndex" | jsonify -}}
|