hugo-theme-relearn/layouts/partials/search.html

72 lines
4.6 KiB
HTML
Raw Normal View History

{{- if not .Site.Params.disableSearch }}
2024-09-11 18:22:53 +00:00
{{- $assetBusting := partialCached "assetbusting.gotmpl" . }}
2022-11-17 16:29:01 +00:00
{{- $link := "" }}
{{- with .Site.Home.OutputFormats.Get "json" }}
{{- warnf "UNSUPPORTED usage of 'json' output format found, remove it from your config; see https://mcshelby.github.io/hugo-theme-relearn/basics/releasenotes/7/#7-0-0" }}
{{- end }}
{{- with .Site.Home.OutputFormats.Get "search" }}
{{- warnf "UNSUPPORTED usage of 'search' output format found, remove it from your config; see https://mcshelby.github.io/hugo-theme-relearn/basics/releasenotes/7/#7-0-0" }}
{{- end }}
{{- with .Site.Home.OutputFormats.Get "searchpage" }}
2024-09-18 18:47:07 +00:00
{{- warnf "UNSUPPORTED usage of 'searchpage' output format found, remove it from your config; see https://mcshelby.github.io/hugo-theme-relearn/basics/releasenotes/7/#7-0-0" }}
{{- 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") "/") }}
{{- 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 }}
<script>
window.index_js_url={{ (printf "%s%s" $url $assetBusting) | relLangURL }};
</script>
{{- if not .Site.Params.disableSearchPage }}
{{- with .Site.GetPage "_relearn_searchpage" }}
{{- $link = partial "permalink.gotmpl" (dict "to" .) }}
{{- end }}
{{- 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>
{{- $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 }}
{{- $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" . }}
{{- if partialCached "_relearn/fileExists.gotmpl" $f $f }}
{{- $quotedcontentlangs = $quotedcontentlangs | append (printf "'%s'" .) }}
{{- else }}
{{- $missingcontentlangs = $missingcontentlangs | append . }}
{{- end }}
2022-06-12 17:24:14 +00:00
{{- end }}
{{- $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>
<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>
{{- $tinyseg := false }}
{{- $wordcut := false }}
2022-06-12 17:24:14 +00:00
{{- range $contentlangs }}
{{- if and (not $tinyseg) (or (eq . "ja")) }}
{{- $tinyseg = true }}
<script src="{{"js/lunr/tinyseg.js" | relURL}}{{ $assetBusting }}" defer></script>
{{- end }}
{{- if and (not $wordcut) (or (eq . "hi") (eq . "th")) }}
{{- $wordcut = true }}
<script src="{{"js/lunr/wordcut.js" | relURL}}{{ $assetBusting }}" defer></script>
{{- end }}
2022-12-29 23:39:07 +00:00
{{- $file := (printf "js/lunr/lunr.%s.min.js" .) }}
<script src="{{ $file | relURL}}{{ $assetBusting }}" defer></script>
2022-06-12 17:24:14 +00:00
{{- end }}
<script src="{{ "js/search.js" | relURL }}{{ $assetBusting }}" defer></script>
{{- end }}