mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 07:47:54 +00:00
search: make build and js forgiving against config errors #400
This commit is contained in:
parent
e738c3c0fd
commit
8aeb69fa56
3 changed files with 8 additions and 3 deletions
|
@ -1,6 +1,8 @@
|
|||
{{- $link := "" }}
|
||||
{{- with .Site.Home.OutputFormats.Get "SEARCHPAGE" }}
|
||||
{{- $link = partial "relLangPrettyUglyURL.hugo" (dict "to" .) }}
|
||||
{{- 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 }}
|
||||
{{- 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 }}
|
||||
|
|
|
@ -117,7 +117,7 @@ function search(term) {
|
|||
// Find the item in our index corresponding to the lunr one to have more info
|
||||
// Remove Lunr special search characters: https://lunrjs.com/guides/searching.html
|
||||
var searchTerm = lunr.tokenizer(term.replace(/[*:^~+-]/, ' ')).reduce( function(a,token){return a.concat(searchPatterns(token.str))}, []).join(' ');
|
||||
return !searchTerm ? [] : lunrIndex.search(searchTerm).map(function(result) {
|
||||
return !searchTerm || !lunrIndex ? [] : lunrIndex.search(searchTerm).map(function(result) {
|
||||
return { index: result.ref, matches: Object.keys(result.matchData.metadata) }
|
||||
});
|
||||
}
|
||||
|
|
|
@ -523,6 +523,9 @@ function printShortcutHandler( event ){
|
|||
|
||||
function showSearch(){
|
||||
var s = document.querySelector( '#search-by' );
|
||||
if( !s ){
|
||||
return;
|
||||
}
|
||||
var b = document.querySelector( 'body' );
|
||||
if( s == document.activeElement ){
|
||||
if( b.classList.contains( 'sidebar-flyout' ) ){
|
||||
|
|
Loading…
Reference in a new issue