{{- $defaultLang := .Sites.First.Language.Lang }} {{- $multihost := partialCached "search/functions/is-multihost" . }} {{- $langs := newScratch }} {{- range .Site.Languages }} {{- $langs.Set .Lang (dict "lang" .Lang "name" .LanguageName) }} {{- end }} {{/* years. */}} {{- $years := slice }} {{- if default true site.Params.search.filter_years }} {{- $indexAllPages := default true .Site.Params.search.index_all_pages }} {{- $pages := .Site.AllPages }} {{- if not $indexAllPages }} {{- $pages = where $pages "kind" "page" }} {{- end }} {{- $pages = where $pages "Params.noindex" "ne" true }} {{- with $pages.GroupByDate "2006" }} {{- range . }} {{- if eq .Key "0001" }} {{- continue }} {{- end }} {{- $years = $years | append .Key }} {{- end }} {{- $years = sort $years }} {{- end }} {{- end }} {{/* taxonomies. */}} {{- $taxonomies := newScratch }} {{- if default true site.Params.search.filter_taxonomies }} {{- $allTaxonomies := newScratch }} {{- range .Site.Sites }} {{- range $name, $taxonomy := .Taxonomies }} {{- range $taxonomy }} {{- $allTaxonomies.Add $name (slice .Page.Title) }} {{- end }} {{- end }} {{- end }} {{/* remove duplicate taxonomies. */}} {{- range $name, $v := $allTaxonomies.Values }} {{- $taxonomies.Set $name ($v | uniq) }} {{- end }} {{- end }} {{- $taxonomyKeys := slice }} {{- range $name, $v := .Site.Taxonomies }} {{- $taxonomyKeys = $taxonomyKeys | append $name }} {{- end }} {{/* i18n messages. */}} {{- $i18n := newScratch }} {{- range $lang, $messages := .Site.Data.search.i18n }} {{/* Exclude the unused messages. */}} {{- if isset $langs.Values $lang }} {{- $i18n.Set $lang $messages }} {{- end }} {{- end }} {{- $js := resources.Get "search/js/index.ts" }} {{/* The SVG icons. */}} {{- $icons := dict "page" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "file-earmark-richtext" "size" "2em")) "heading" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "hash" "size" "2em")) "history" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "clock" "size" "2em")) "meta" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "info-circle" "size" "2em")) "search" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "search" "size" "1.25em")) "spinner" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "arrow-clockwise" "size" "1.35em")) "lang" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "translate" "size" "1em")) "sort" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "sort-down" "size" "1em")) "expand" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "chevron-expand" "size" "1em")) "year" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "calendar-check" "size" "1em")) "taxonomies" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "tags" "size" "1em")) }} {{/* Include the following icons when necessary. */}} {{- if default true .Site.Params.search.index_all_pages }} {{- $icons = merge $icons (dict "home" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "house" "size" "2em")) "section" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "list" "size" "2em")) "term" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "tag" "size" "2em")) "taxonomy" (partial "icons/icon" (dict "vendor" "bootstrap" "name" "tags" "size" "2em"))) }} {{- end }} {{/* Index files URL. */}} {{- $indices := slice }} {{- range .Sites }} {{- $site := . }} {{- with .Home.OutputFormats.Get "SearchIndex" }} {{- $hash := partialCached "search/functions/search-index-hash" $site $site }} {{- $indexURL := printf "%s?v=%s" (cond $multihost .Permalink .RelPermalink) $hash }} {{- $indices = $indices | append $indexURL }} {{- end }} {{- end }} {{- $defaultParams := partialCached "search/functions/params" . }} {{- $params := merge $defaultParams (dict "icons" $icons "indices" $indices "i18n" $i18n.Values "historiesCount" (default 5 site.Params.search.histories_count) "defaultLang" $defaultLang "langs" $langs.Values "years" $years "taxonomies" $taxonomies.Values "taxonomyKeys" $taxonomyKeys) }} {{- $options := dict "targetPath" "js/search.js" "minify" hugo.IsProduction "params" $params }} {{- $js = $js | js.Build $options }} {{- return $js -}}