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 `<span class="lnt?"> *\d*\n?</span>` "" -}} - {{- range $i, $contenti := split $content "<h2 id=" -}} - {{- if gt $i 0 -}} - {{- $contenti = printf "<h2 id=%v" $contenti -}} + {{- $anchor := "" -}} + {{- range $h, $contenth := split $content "<h1 id=" -}} + {{- if gt $h 0 -}} + {{- $anchor = replace (index (split $contenth ">") 0) `"` "" -}} + {{- $contenth = printf "<h1 id=%v" $contenth -}} {{- end -}} - {{- range $j, $contentj := split $contenti "<h3 id=" -}} - {{- if gt $j 0 -}} - {{- $contentj = printf "<h3 id=%v" $contentj -}} + {{- range $i, $contenti := split $contenth "<h2 id=" -}} + {{- if gt $i 0 -}} + {{- $anchor = replace (index (split $contenti ">") 0) `"` "" -}} + {{- $contenti = printf "<h2 id=%v" $contenti -}} {{- end -}} - {{/* Plainify, unescape and remove (\n, \t) */}} - {{- $contentj = $contentj | plainify | htmlUnescape | replaceRE `[\n\t ]+` " " -}} - {{- if gt $.Site.Params.search.contentLength 0 -}} - {{- $contentj = substr $contentj 0 $.Site.Params.search.contentLength -}} - {{- end -}} - {{- if $contentj | and (ne $contentj " ") -}} - {{- $one := printf "%v:%v:%v" $uri $i $j | dict "content" $contentj "objectID" | merge $meta -}} - {{- $index = $index | append $one -}} + {{- range $j, $contentj := split $contenti "<h3 id=" -}} + {{- if gt $j 0 -}} + {{- $anchor = replace (index (split $contentj ">") 0) `"` "" -}} + {{- $contentj = printf "<h3 id=%v" $contentj -}} + {{- end -}} + {{- range $k, $contentk := split $contentj "<h4 id=" -}} + {{- if gt $k 0 -}} + {{- $anchor = replace (index (split $contentk ">") 0) `"` "" -}} + {{- $contentk = printf "<h4 id=%v" $contentk -}} + {{- end -}} + {{- range $l, $contentl := split $contentk "<h5 id=" -}} + {{- if gt $l 0 -}} + {{- $anchor = replace (index (split $contentl ">") 0) `"` "" -}} + {{- $contentk = printf "<h5 id=%v" $contentl -}} + {{- end -}} + {{- range $m, $contentm := split $contentl "<h6 id=" -}} + {{- if gt $m 0 -}} + {{- $anchor = replace (index (split $contentm ">") 0) `"` "" -}} + {{- $contentm = printf "<h6 id=%v" $contentm -}} + {{- end -}} + {{/* Plainify, unescape and remove (\n, \t) */}} + {{- $contentj = $contentj | plainify | htmlUnescape | replaceRE `[\n\t ]+` " " -}} + {{- if gt $.Site.Params.search.contentLength 0 -}} + {{- $contentj = substr $contentj 0 $.Site.Params.search.contentLength -}} + {{- end -}} + {{- if $contentj | and (ne $contentj " ") -}} + {{- $one := printf "%v:%v:%v" $uri $i $j | dict "content" $contentj "uri" (printf "%v#%v" $uri $anchor) "objectID" | merge $meta -}} + {{- $index = $index | append $one -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} {{- end -}} {{- end -}} {{- end -}}