2 more search options: searchContent, searchDistance
This commit is contained in:
parent
438cc9561c
commit
272be8ac88
|
@ -268,10 +268,14 @@ showMobileMenuTerms = ["tags", "categories", "series"]
|
||||||
# navbar
|
# navbar
|
||||||
enableThemeChange = true # site color theme
|
enableThemeChange = true # site color theme
|
||||||
|
|
||||||
# body
|
# search
|
||||||
enableBreadcrumb = true # breadcrumb for list, single page
|
|
||||||
enableSearch = true # site search with fuse
|
enableSearch = true # site search with fuse
|
||||||
enableSearchHighlight = true # when true, search keyword will be highlighted
|
enableSearchHighlight = true # when true, search keyword will be highlighted
|
||||||
|
searchContent = true # include content to search index
|
||||||
|
searchDistance = 100 # fuse option: distance
|
||||||
|
|
||||||
|
# body
|
||||||
|
enableBreadcrumb = true # breadcrumb for list, single page
|
||||||
enableGoToTop = true # scroll to top
|
enableGoToTop = true # scroll to top
|
||||||
enableWhoami = true # at the end of single page
|
enableWhoami = true # at the end of single page
|
||||||
summaryShape = "classic" # card, classic, compact
|
summaryShape = "classic" # card, classic, compact
|
||||||
|
|
|
@ -30,15 +30,18 @@ hideHomeHeaderWhenMobile = false
|
||||||
# menu
|
# menu
|
||||||
showMobileMenuTerms = ["tags", "categories", "series"]
|
showMobileMenuTerms = ["tags", "categories", "series"]
|
||||||
|
|
||||||
# body
|
# search
|
||||||
enableBreadcrumb = true
|
|
||||||
enablePhotoSwipe = true
|
|
||||||
enableSearch = true
|
enableSearch = true
|
||||||
enableSearchHighlight = true
|
enableSearchHighlight = true
|
||||||
|
searchResultPosition = "main" # side, main
|
||||||
|
searchContent = true # include content to search index
|
||||||
|
searchDistance = 100 # fuse option
|
||||||
|
|
||||||
|
# body
|
||||||
|
enableBreadcrumb = true
|
||||||
enableGoToTop = true
|
enableGoToTop = true
|
||||||
enableWhoami = true
|
enableWhoami = true
|
||||||
summaryShape = "classic" # card, classic, compact
|
summaryShape = "classic" # card, classic, compact
|
||||||
searchResultPosition = "main" # side, main
|
|
||||||
archiveGroupByDate = "2006" # "2006-01": group by month, "2006": group by year
|
archiveGroupByDate = "2006" # "2006-01": group by month, "2006": group by year
|
||||||
archivePaginate = 13
|
archivePaginate = 13
|
||||||
paginateWindow = 1
|
paginateWindow = 1
|
||||||
|
|
|
@ -2,7 +2,11 @@
|
||||||
{{- $.Scratch.Add "searchindex" slice -}}
|
{{- $.Scratch.Add "searchindex" slice -}}
|
||||||
{{- range $index, $element := (where .Site.RegularPages "Kind" "page") -}}
|
{{- range $index, $element := (where .Site.RegularPages "Kind" "page") -}}
|
||||||
{{ with $element.Plain }}
|
{{ 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 }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- $.Scratch.Get "searchindex" | jsonify -}}
|
{{- $.Scratch.Get "searchindex" | jsonify -}}
|
|
@ -662,6 +662,10 @@
|
||||||
|
|
||||||
{{ $enableSearch := ($.Param "enableSearch") }}
|
{{ $enableSearch := ($.Param "enableSearch") }}
|
||||||
var enableSearch = JSON.parse({{ $enableSearch | jsonify }});
|
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") }}
|
{{ $enableSearchHighlight := ($.Param "enableSearchHighlight") }}
|
||||||
var enableSearchHighlight = JSON.parse({{ $enableSearchHighlight | jsonify }});
|
var enableSearchHighlight = JSON.parse({{ $enableSearchHighlight | jsonify }});
|
||||||
{{ $searchResultPosition := ($.Param "searchResultPosition") }}
|
{{ $searchResultPosition := ($.Param "searchResultPosition") }}
|
||||||
|
@ -686,12 +690,13 @@
|
||||||
xhr.onload = function () {
|
xhr.onload = function () {
|
||||||
if (xhr.status === 200) {
|
if (xhr.status === 200) {
|
||||||
fuse = new Fuse(JSON.parse(xhr.response.toString('utf-8')), {
|
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,
|
includeMatches: enableSearchHighlight,
|
||||||
shouldSort: true, // default: true
|
shouldSort: true, // default: true
|
||||||
threshold: 0.4, // default: 0.6 (0.0 requires a perfect match)
|
threshold: 0.4, // default: 0.6 (0.0 requires a perfect match)
|
||||||
location: 0, // default: 0
|
location: 0, // default: 0
|
||||||
distance: 100, // default: 100
|
distance: searchDistance ? searchDistance : 100, // default: 100
|
||||||
maxPatternLength: 32,
|
maxPatternLength: 32,
|
||||||
minMatchCharLength: 1,
|
minMatchCharLength: 1,
|
||||||
isCaseSensitive: false, // defualt: false
|
isCaseSensitive: false, // defualt: false
|
||||||
|
|
Loading…
Reference in New Issue