Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zzossig/hugo-theme-zzo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzzossig <zzossig@gmail.com>2021-04-19 22:46:56 +0300
committerzzossig <zzossig@gmail.com>2021-04-19 22:46:56 +0300
commit272be8ac8836cbd1d595594497810ab8576719d9 (patch)
treea3148ff24394f8b1d789cf5f700f59f8052e1ce4 /layouts
parent438cc9561c5ed0d60075f6a52f5f2a122a70c66a (diff)
2 more search options: searchContent, searchDistance
Diffstat (limited to 'layouts')
-rw-r--r--layouts/index.json6
-rw-r--r--layouts/partials/head/scripts.html9
2 files changed, 12 insertions, 3 deletions
diff --git a/layouts/index.json b/layouts/index.json
index 98a3da9..d2ba08a 100644
--- a/layouts/index.json
+++ b/layouts/index.json
@@ -2,7 +2,11 @@
{{- $.Scratch.Add "searchindex" slice -}}
{{- range $index, $element := (where .Site.RegularPages "Kind" "page") -}}
{{ with $element.Plain }}
- {{- $.Scratch.Add "searchindex" (dict "id" $index "title" $element.Title "uri" $element.Permalink "tags" $element.Params.tags "section" $element.Section "content" $element.Plain "description" $element.Description) -}}
+ {{- if $.Param "searchContent" -}}
+ {{- $.Scratch.Add "searchindex" (dict "id" $index "title" $element.Title "uri" $element.Permalink "tags" $element.Params.tags "section" $element.Section "content" $element.Plain "description" $element.Description) -}}
+ {{ else }}
+ {{- $.Scratch.Add "searchindex" (dict "id" $index "title" $element.Title "uri" $element.Permalink "tags" $element.Params.tags "section" $element.Section "description" $element.Description) -}}
+ {{- end -}}
{{ end }}
{{- end -}}
{{- $.Scratch.Get "searchindex" | jsonify -}} \ No newline at end of file
diff --git a/layouts/partials/head/scripts.html b/layouts/partials/head/scripts.html
index ec2514f..cf2d608 100644
--- a/layouts/partials/head/scripts.html
+++ b/layouts/partials/head/scripts.html
@@ -662,6 +662,10 @@
{{ $enableSearch := ($.Param "enableSearch") }}
var enableSearch = JSON.parse({{ $enableSearch | jsonify }});
+ {{ $searchDistance := ($.Param "searchDistance") }}
+ var searchDistance = JSON.parse({{ $searchDistance | jsonify }});
+ {{ $searchContent := ($.Param "searchContent") }}
+ var searchContent = JSON.parse({{ $searchContent | jsonify }});
{{ $enableSearchHighlight := ($.Param "enableSearchHighlight") }}
var enableSearchHighlight = JSON.parse({{ $enableSearchHighlight | jsonify }});
{{ $searchResultPosition := ($.Param "searchResultPosition") }}
@@ -686,12 +690,13 @@
xhr.onload = function () {
if (xhr.status === 200) {
fuse = new Fuse(JSON.parse(xhr.response.toString('utf-8')), {
- keys: sectionType.includes('publication') ? ['title', 'abstract'] : ['title', 'description', 'content'],
+ keys: sectionType.includes('publication') ? ['title', 'abstract'] :
+ searchContent ? ['title', 'description', 'content'] : ['title', 'description'],
includeMatches: enableSearchHighlight,
shouldSort: true, // default: true
threshold: 0.4, // default: 0.6 (0.0 requires a perfect match)
location: 0, // default: 0
- distance: 100, // default: 100
+ distance: searchDistance ? searchDistance : 100, // default: 100
maxPatternLength: 32,
minMatchCharLength: 1,
isCaseSensitive: false, // defualt: false