2024-08-26 21:07:33 +00:00
{{- if not .Site.Params.disableSearch }}
2024-08-29 10:28:34 +00:00
{{- $assetBusting := partialCached "_relearn/assetbusting.gotmpl" . }}
2022-11-17 16:29:01 +00:00
{{- $link := "" }}
2024-04-26 21:35:56 +00:00
{{- with .Site.Home.OutputFormats.Get "json" }}
{{- warnf "UNSUPPORTED usage of 'json' output format found, use 'search' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration#600" }}
{{- end }}
2024-08-26 21:07:33 +00:00
{{- with .Site.Home.OutputFormats.Get "searchpage" }}
{{- warnf "UNSUPPORTED usage of 'searchpage' output format found, remove it from your config; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration#700" }}
{{- end }}
{{- if not .Site.Params.disableSearchIndex }}
2024-08-26 22:35:12 +00:00
{{- $url := path.Join .Site.LanguagePrefix (trim (or .Site.Params.searchIndexURL "searchindex.js") "/") }}
2024-08-29 22:28:52 +00:00
{{- if .IsHome }}
{{- $templateres := resources.Get "_relearn_searchindex.js" }}
{{- $resultres := $templateres | resources.ExecuteAsTemplate $url .Site.Home }}
{{- /* the following code causes Hugo to generate our file - although it is in comments */}}<!-- {{ $resultres.RelPermalink }} -->
{{- end }}
2024-08-26 21:07:33 +00:00
< script >
window.index_js_url={{ (printf "%s%s" $url $assetBusting) | relLangURL }};
< / script >
{{- if not .Site.Params.disableSearchPage }}
{{- with .Site.GetPage "_relearn_searchpage" }}
2024-08-29 10:28:34 +00:00
{{- $link = partial "permalink.gotmpl" (dict "to" .) }}
2024-08-26 21:07:33 +00:00
{{- end }}
2022-11-20 22:00:40 +00:00
{{- end }}
2022-11-17 16:29:01 +00:00
{{- end }}
2024-04-04 15:49:28 +00:00
< search > {{ if $link }}< form action = "{{ $link }}" method = "get" > {{ end }}
< div class = "searchbox default-animation" >
{{ if $link }}< button class = "search-detail" type = "submit" title = "{{ T " Search " } } ( CTRL + ALT + f ) " > {{ end }}< i class = "fas fa-search" { { if not $ link } } title = "{{ T " Search " } } ( CTRL + ALT + f ) " { { end } } > < / i > {{ if $link }}< / button > {{ end }}
< label class = "a11y-only" for = "R-search-by" > {{ T "Search" }}< / label >
< input data-search-input id = "R-search-by" name = "search-by" class = "search-by" type = "search" placeholder = "{{ T " Search-placeholder " } } " >
< button class = "search-clear" type = "button" data-search-clear = "" title = "{{ T " Clear-search " } } " > < i class = "fas fa-times" title = "{{ T " Clear-search " } } " > < / i > < / button >
< / div >
{{ if $link }}< / form > {{ end }}< / search >
2023-11-28 20:31:35 +00:00
{{- $pageBaseLang := replaceRE "([a-z]+).*" "${1}" .Page.Language.LanguageCode }}
2023-06-22 15:51:18 +00:00
{{- $contentlangs := (union (slice | append (.Site.Params.additionalContentLanguage | default slice)) (slice $pageBaseLang)) }}
2022-06-12 17:24:14 +00:00
{{- $quotedcontentlangs := slice }}
2022-06-22 19:40:59 +00:00
{{- $missingcontentlangs := slice }}
2022-06-12 17:24:14 +00:00
{{- range $contentlangs }}
2022-12-29 23:39:07 +00:00
{{- $f := printf "/static/js/lunr/lunr.%s.min.js" . }}
2024-08-29 10:28:34 +00:00
{{- if partialCached "_relearn/fileExists.gotmpl" $f $f }}
2022-06-22 19:40:59 +00:00
{{- $quotedcontentlangs = $quotedcontentlangs | append (printf "'%s'" .) }}
{{- else }}
{{- $missingcontentlangs = $missingcontentlangs | append . }}
{{- end }}
2022-06-12 17:24:14 +00:00
{{- end }}
2022-06-22 19:40:59 +00:00
{{- $contentlangs = $contentlangs | complement $missingcontentlangs }}
2022-06-12 12:05:01 +00:00
< script >
2022-06-12 17:24:14 +00:00
var contentLangs=[{{ delimit $quotedcontentlangs ", " | safeJS }}];
2022-06-12 12:05:01 +00:00
< / script >
2024-07-04 06:23:54 +00:00
< script src = "{{" js / auto-complete . js " | relURL } } { { $ assetBusting } } " defer > < / script >
< script src = "{{" js / lunr / lunr . min . js " | relURL } } { { $ assetBusting } } " defer > < / script >
< script src = "{{" js / lunr / lunr . stemmer . support . min . js " | relURL } } { { $ assetBusting } } " defer > < / script >
< script src = "{{" js / lunr / lunr . multi . min . js " | relURL } } { { $ assetBusting } } " defer > < / script >
2022-12-30 00:09:07 +00:00
{{- $tinyseg := false }}
{{- $wordcut := false }}
2022-06-12 17:24:14 +00:00
{{- range $contentlangs }}
2022-12-30 00:09:07 +00:00
{{- if and (not $tinyseg) (or (eq . "ja")) }}
{{- $tinyseg = true }}
2024-07-04 06:23:54 +00:00
< script src = "{{" js / lunr / tinyseg . js " | relURL } } { { $ assetBusting } } " defer > < / script >
2022-12-30 00:09:07 +00:00
{{- end }}
{{- if and (not $wordcut) (or (eq . "hi") (eq . "th")) }}
{{- $wordcut = true }}
2024-07-04 06:23:54 +00:00
< script src = "{{" js / lunr / wordcut . js " | relURL } } { { $ assetBusting } } " defer > < / script >
2022-12-30 00:09:07 +00:00
{{- end }}
2022-12-29 23:39:07 +00:00
{{- $file := (printf "js/lunr/lunr.%s.min.js" .) }}
2024-07-04 06:23:54 +00:00
< script src = "{{ $file | relURL}}{{ $assetBusting }}" defer > < / script >
2022-06-12 17:24:14 +00:00
{{- end }}
2024-08-26 21:07:33 +00:00
< script src = "{{ " js / search . js " | relURL } } { { $ assetBusting } } " defer > < / script >
{{- end }}