{{- /* 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 }} {{- $publishDate := $page.PublishDate -}} {{- if $publishDate.IsZero -}} {{ $publishDate = now -}} {{- end -}} {{- $modifiedDate := $page.Lastmod -}} {{- if $modifiedDate.IsZero -}} {{ $modifiedDate = $publishDate -}} {{- end -}} {{- $pageData := (dict "objectID" $page.File.UniqueID "title" $page.Title "href" $page.Permalink "lang" ($page.Params.lang | default $page.Lang) "tags" ($page.Params.tags | default slice) "kind" $page.Kind "type" $page.Type "section" $page.Section "content" (trim $page.Plain "\n ") "publishDate" $publishDate "lastmod" $modifiedDate ) -}} {{- $.Scratch.Add "pagesIndex" $pageData -}} {{- $.Scratch.Add "urlsAdded" $page.Permalink -}} {{- end -}} {{- end -}} {{- end -}} {{- end -}} {{- end -}} {{- $.Scratch.Get "pagesIndex" | jsonify -}}