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

38 lines
2.7 KiB
HTML
Raw Normal View History

2022-11-17 16:29:01 +00:00
{{- $link := "" }}
{{- if or (.Site.Home.OutputFormats.Get "JSON") (.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 }}
{{- $c:="" }} {{ if $link }}<form action="{{ $link }}" method="get">{{ end }}<div class="searchbox default-animation">
{{ if $link }}<button 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="search-by">{{ T "Search" }}</label>
2022-11-17 16:29:01 +00:00
<input data-search-input id="search-by" name="search-by" class="search-by" type="search" placeholder="{{ T "Search-placeholder" }}">
2021-09-12 08:33:24 +00:00
<span data-search-clear=""><i class="fas fa-times"></i></span>
2022-11-17 16:29:01 +00:00
</div>{{ if $link }}</form>{{ end }}
2021-09-12 08:33:24 +00:00
{{- $assetBusting := not .Site.Params.disableAssetsBusting }}
2022-06-12 12:05:01 +00:00
{{- $pageBaseLang := replaceRE "([a-z]+).*" "${1}" .Page.Lang }}
{{- $contentlangs := (union (slice | append .Site.Params.additionalContentLanguage) (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>
2022-06-12 17:24:14 +00:00
{{- range $contentlangs }}
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>