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

53 lines
3.6 KiB
HTML
Raw Normal View History

2022-11-17 16:29:01 +00:00
{{- $link := "" }}
{{- 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 }}
{{- if .Site.Home.OutputFormats.Get "search" }}
{{- with .Site.Home.OutputFormats.Get "searchpage" }}
{{- $link = partial "relLangPrettyUglyURL.hugo" (dict "to" .) }}
{{- 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>
2021-09-12 08:33:24 +00:00
{{- $assetBusting := not .Site.Params.disableAssetsBusting }}
{{- $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" . }}
2022-11-12 14:16:53 +00:00
{{- if partialCached "fileExists.hugo" $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}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" defer></script>
2022-12-29 23:39:07 +00:00
<script src="{{"js/lunr/lunr.min.js" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" defer></script>
<script src="{{"js/lunr/lunr.stemmer.support.min.js" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" defer></script>
<script src="{{"js/lunr/lunr.multi.min.js" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" 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}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" defer></script>
{{- end }}
{{- if and (not $wordcut) (or (eq . "hi") (eq . "th")) }}
{{- $wordcut = true }}
<script src="{{"js/lunr/wordcut.js" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" defer></script>
{{- end }}
2022-12-29 23:39:07 +00:00
{{- $file := (printf "js/lunr/lunr.%s.min.js" .) }}
<script src="{{ $file | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" defer></script>
2022-06-12 17:24:14 +00:00
{{- end }}
<script src="{{ "js/search.js" | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" defer></script>