From 0b5c6797ee8e2ce6cc103dce81c064e481bb7a0a Mon Sep 17 00:00:00 2001 From: PCloud <52968553+HEIGE-PCloud@users.noreply.github.com> Date: Sat, 2 Oct 2021 12:08:18 +0100 Subject: [PATCH] feat: enhance searching experience (#260) * feat: enhance index.js - add anchor information to uri - add support from h4 to h6 * chore(fusejs): adjust fusejs search settings * feat: add support for h1 tag * chore: tweak the search settings --- exampleSite/config.toml | 10 +++---- layouts/index.json | 59 ++++++++++++++++++++++++++++++----------- 2 files changed, 48 insertions(+), 21 deletions(-) diff --git a/exampleSite/config.toml b/exampleSite/config.toml index b6d0c6ed6..834db4549 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -136,7 +136,7 @@ enableEmoji = true # max number of results length maxResultLength = 10 # snippet length of the result - snippetLength = 30 + snippetLength = 300 # HTML tag name of the highlight part in results highlightTag = "em" # whether to use the absolute URL based on the baseURL in search index @@ -151,9 +151,9 @@ enableEmoji = true minMatchCharLength = 2 findAllMatches = false location = 0 - threshold = 0.3 + threshold = 0.1 distance = 100 - ignoreLocation = false + ignoreLocation = true useExtendedSearch = false ignoreFieldNorm = false # Home page config @@ -381,9 +381,9 @@ enableEmoji = true minMatchCharLength = 2 findAllMatches = false location = 0 - threshold = 0.3 + threshold = 0.1 distance = 100 - ignoreLocation = false + ignoreLocation = true useExtendedSearch = false ignoreFieldNorm = false # 主页信息设置 diff --git a/layouts/index.json b/layouts/index.json index cc62c33e0..5ed471d77 100644 --- a/layouts/index.json +++ b/layouts/index.json @@ -11,32 +11,59 @@ {{- if $.Site.Params.search.absoluteURL -}} {{- $uri = .Permalink -}} {{- end -}} - {{- $meta := dict "uri" $uri "title" .Title "tags" .Params.tags "categories" .Params.categories "series" .Params.series -}} + {{- $meta := dict "title" .Title "tags" .Params.tags "categories" .Params.categories "series" .Params.series -}} {{- $meta = $.Site.Params.dateFormat | default "2006-01-02" | .PublishDate.Format | dict "date" | merge $meta -}} {{- with .Description -}} - {{- $index = $index | append (dict "content" . "objectID" $uri | merge $meta) -}} + {{- $index = $index | append (dict "content" . "objectID" $uri "uri" $uri| merge $meta) -}} {{- end -}} {{- $params := .Params | merge $.Site.Params.page -}} {{/* Extended Markdown syntax */}} {{- $content := dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" -}} {{/* Remove line number for code */}} {{- $content = $content | replaceRE ` *\d*\n?` "" -}} - {{- range $i, $contenti := split $content "