Skip to content

Commit 9b49519

Browse files
committed
Add redirect from previous search url
1 parent 740c4b9 commit 9b49519

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

layouts/partials/search.html

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{{- if not .Site.Params.disableSearch }}
2+
{{- $assetBusting := partialCached "assetbusting.gotmpl" . }}
3+
{{- $link := "" }}
4+
{{- with .Site.Home.OutputFormats.Get "json" }}
5+
{{- warnf "UNSUPPORTED usage of 'json' output format found, remove it from your config; see https://mcshelby.github.io/hugo-theme-relearn/introduction/releasenotes/7/#7-0-0" }}
6+
{{- end }}
7+
{{- with .Site.Home.OutputFormats.Get "search" }}
8+
{{- warnf "UNSUPPORTED usage of 'search' output format found, remove it from your config; see https://mcshelby.github.io/hugo-theme-relearn/introduction/releasenotes/7/#7-0-0" }}
9+
{{- end }}
10+
{{- with .Site.Home.OutputFormats.Get "searchpage" }}
11+
{{- warnf "UNSUPPORTED usage of 'searchpage' output format found, remove it from your config; see https://mcshelby.github.io/hugo-theme-relearn/introduction/releasenotes/7/#7-0-0" }}
12+
{{- end }}
13+
{{- if not .Site.Params.disableSearchIndex }}
14+
{{- $url := trim (or .Site.Params.searchIndexURL "searchindex.js") "/" }}
15+
{{- $url = path.Join (path.Dir $url) (print (path.BaseName $url) "." .Language.Lang (path.Ext $url)) }}
16+
{{- if .IsHome }}
17+
{{- $templateres := resources.Get "_relearn_searchindex.js" }}
18+
{{- $resultres := $templateres | resources.ExecuteAsTemplate $url .Site.Home }}
19+
{{- /* the following code causes Hugo to generate our file - although it is in comments */}}<!-- {{ $resultres.RelPermalink }} -->
20+
{{- end }}
21+
<script>
22+
window.index_js_url={{ (printf "%s%s" $url $assetBusting) | relURL }};
23+
</script>
24+
{{- if not .Site.Params.disableSearchPage }}
25+
{{- with .Site.GetPage "/_relearn/searchpage/_relearn_searchpage" }}
26+
{{- $link = partial "permalink.gotmpl" (dict "to" .) }}
27+
{{- end }}
28+
{{- end }}
29+
{{- end }}
30+
<search>{{ if $link }}<form action="{{ $link }}" method="get">{{ end }}
31+
<div class="searchbox default-animation">
32+
{{ 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 }}
33+
<label class="a11y-only" for="R-search-by">{{ T "Search" }}</label>
34+
<input data-search-input id="R-search-by" name="search-by" class="search-by" type="search" placeholder="{{ T "Search-placeholder" }}">
35+
<button class="search-clear" type="button" data-search-clear="" title="{{ T "Clear-search" }}"><i class="fas fa-times" title="{{ T "Clear-search" }}"></i></button>
36+
</div>
37+
{{ if $link }}</form>{{ end }}</search>
38+
{{- $pageBaseLang := replaceRE "([a-z]+).*" "${1}" .Page.Language.LanguageCode }}
39+
{{- $contentlangs := (union (slice | append (.Site.Params.additionalContentLanguage | default slice)) (slice $pageBaseLang)) }}
40+
{{- $quotedcontentlangs := slice }}
41+
{{- $missingcontentlangs := slice }}
42+
{{- range $contentlangs }}
43+
{{- $f := printf "/static/js/lunr/lunr.%s.min.js" . }}
44+
{{- if partialCached "_relearn/fileExists.gotmpl" $f $f }}
45+
{{- $quotedcontentlangs = $quotedcontentlangs | append (printf "'%s'" .) }}
46+
{{- else }}
47+
{{- $missingcontentlangs = $missingcontentlangs | append . }}
48+
{{- end }}
49+
{{- end }}
50+
{{- $contentlangs = $contentlangs | complement $missingcontentlangs }}
51+
<script>
52+
var contentLangs=[{{ delimit $quotedcontentlangs ", " | safeJS }}];
53+
</script>
54+
<script src="{{"js/auto-complete.js" | relURL}}{{ $assetBusting }}" defer></script>
55+
<script src="{{"js/lunr/lunr.min.js" | relURL}}{{ $assetBusting }}" defer></script>
56+
<script src="{{"js/lunr/lunr.stemmer.support.min.js" | relURL}}{{ $assetBusting }}" defer></script>
57+
<script src="{{"js/lunr/lunr.multi.min.js" | relURL}}{{ $assetBusting }}" defer></script>
58+
{{- $tinyseg := false }}
59+
{{- $wordcut := false }}
60+
{{- range $contentlangs }}
61+
{{- if and (not $tinyseg) (or (eq . "ja")) }}
62+
{{- $tinyseg = true }}
63+
<script src="{{"js/lunr/tinyseg.js" | relURL}}{{ $assetBusting }}" defer></script>
64+
{{- end }}
65+
{{- if and (not $wordcut) (or (eq . "hi") (eq . "th")) }}
66+
{{- $wordcut = true }}
67+
<script src="{{"js/lunr/wordcut.js" | relURL}}{{ $assetBusting }}" defer></script>
68+
{{- end }}
69+
{{- $file := (printf "js/lunr/lunr.%s.min.js" .) }}
70+
<script src="{{ $file | relURL}}{{ $assetBusting }}" defer></script>
71+
{{- end }}
72+
<script src="{{ "js/search.js" | relURL }}{{ $assetBusting }}" defer></script>
73+
<script>
74+
(function() {
75+
const urlParams = new URLSearchParams(window.location.search);
76+
const searchQuery = urlParams.get('q');
77+
if (searchQuery) {
78+
const newUrl = `/search/?search-by=${encodeURIComponent(searchQuery)}`;
79+
window.location.replace(newUrl);
80+
}
81+
})();
82+
</script>
83+
{{- end }}

0 commit comments

Comments
 (0)