feat(search): add absoluteURL config for search index (#302)
This commit is contained in:
@@ -125,6 +125,8 @@ enableEmoji = true
|
|||||||
snippetLength = 30
|
snippetLength = 30
|
||||||
# HTML tag name of the highlight part in results
|
# HTML tag name of the highlight part in results
|
||||||
highlightTag = "em"
|
highlightTag = "em"
|
||||||
|
# whether to use the absolute URL based on the baseURL in search index
|
||||||
|
absoluteURL = false
|
||||||
[languages.en.params.search.algolia]
|
[languages.en.params.search.algolia]
|
||||||
index = "index.en"
|
index = "index.en"
|
||||||
appID = "PASDMWALPK"
|
appID = "PASDMWALPK"
|
||||||
@@ -321,6 +323,8 @@ enableEmoji = true
|
|||||||
snippetLength = 50
|
snippetLength = 50
|
||||||
# 搜索结果中高亮部分的 HTML 标签
|
# 搜索结果中高亮部分的 HTML 标签
|
||||||
highlightTag = "em"
|
highlightTag = "em"
|
||||||
|
# 是否在搜索索引中使用基于 baseURL 的绝对路径
|
||||||
|
absoluteURL = false
|
||||||
[languages.zh-cn.params.search.algolia]
|
[languages.zh-cn.params.search.algolia]
|
||||||
index = "index.zh-cn"
|
index = "index.zh-cn"
|
||||||
appID = "PASDMWALPK"
|
appID = "PASDMWALPK"
|
||||||
@@ -513,6 +517,8 @@ enableEmoji = true
|
|||||||
snippetLength = 30
|
snippetLength = 30
|
||||||
# HTML tag name of the highlight part in results
|
# HTML tag name of the highlight part in results
|
||||||
highlightTag = "em"
|
highlightTag = "em"
|
||||||
|
# whether to use the absolute URL based on the baseURL in search index
|
||||||
|
absoluteURL = false
|
||||||
[languages.fr.params.search.algolia]
|
[languages.fr.params.search.algolia]
|
||||||
index = "index.fr"
|
index = "index.fr"
|
||||||
appID = "PASDMWALPK"
|
appID = "PASDMWALPK"
|
||||||
|
|||||||
@@ -231,6 +231,8 @@ Please open the code block below to view the complete sample configuration :(far
|
|||||||
snippetLength = 30
|
snippetLength = 30
|
||||||
# {{< version 0.2.1 >}} HTML tag name of the highlight part in results
|
# {{< version 0.2.1 >}} HTML tag name of the highlight part in results
|
||||||
highlightTag = "em"
|
highlightTag = "em"
|
||||||
|
# {{< version 0.2.4 >}} whether to use the absolute URL based on the baseURL in search index
|
||||||
|
absoluteURL = false
|
||||||
[params.search.algolia]
|
[params.search.algolia]
|
||||||
index = ""
|
index = ""
|
||||||
appID = ""
|
appID = ""
|
||||||
@@ -987,6 +989,8 @@ Here is the search configuration in your [site configuration](#site-configuratio
|
|||||||
snippetLength = 30
|
snippetLength = 30
|
||||||
# {{< version 0.2.1 >}} HTML tag name of the highlight part in results
|
# {{< version 0.2.1 >}} HTML tag name of the highlight part in results
|
||||||
highlightTag = "em"
|
highlightTag = "em"
|
||||||
|
# {{< version 0.2.4 >}} whether to use the absolute URL based on the baseURL in search index
|
||||||
|
absoluteURL = false
|
||||||
[params.search.algolia]
|
[params.search.algolia]
|
||||||
index = ""
|
index = ""
|
||||||
appID = ""
|
appID = ""
|
||||||
|
|||||||
@@ -236,6 +236,8 @@ Please open the code block below to view the complete sample configuration :(far
|
|||||||
snippetLength = 30
|
snippetLength = 30
|
||||||
# {{< version 0.2.1 >}} HTML tag name of the highlight part in results
|
# {{< version 0.2.1 >}} HTML tag name of the highlight part in results
|
||||||
highlightTag = "em"
|
highlightTag = "em"
|
||||||
|
# {{< version 0.2.4 >}} whether to use the absolute URL based on the baseURL in search index
|
||||||
|
absoluteURL = false
|
||||||
[params.search.algolia]
|
[params.search.algolia]
|
||||||
index = ""
|
index = ""
|
||||||
appID = ""
|
appID = ""
|
||||||
@@ -992,6 +994,8 @@ Here is the search configuration in your [site configuration](#site-configuratio
|
|||||||
snippetLength = 30
|
snippetLength = 30
|
||||||
# {{< version 0.2.1 >}} HTML tag name of the highlight part in results
|
# {{< version 0.2.1 >}} HTML tag name of the highlight part in results
|
||||||
highlightTag = "em"
|
highlightTag = "em"
|
||||||
|
# {{< version 0.2.4 >}} whether to use the absolute URL based on the baseURL in search index
|
||||||
|
absoluteURL = false
|
||||||
[params.search.algolia]
|
[params.search.algolia]
|
||||||
index = ""
|
index = ""
|
||||||
appID = ""
|
appID = ""
|
||||||
|
|||||||
@@ -234,6 +234,8 @@ hugo
|
|||||||
snippetLength = 50
|
snippetLength = 50
|
||||||
# {{< version 0.2.1 >}} 搜索结果中高亮部分的 HTML 标签
|
# {{< version 0.2.1 >}} 搜索结果中高亮部分的 HTML 标签
|
||||||
highlightTag = "em"
|
highlightTag = "em"
|
||||||
|
# {{< version 0.2.4 >}} 是否在搜索索引中使用基于 baseURL 的绝对路径
|
||||||
|
absoluteURL = false
|
||||||
[params.search.algolia]
|
[params.search.algolia]
|
||||||
index = ""
|
index = ""
|
||||||
appID = ""
|
appID = ""
|
||||||
@@ -992,6 +994,8 @@ defaultContentLanguage = "zh-cn"
|
|||||||
snippetLength = 50
|
snippetLength = 50
|
||||||
# {{< version 0.2.1 >}} 搜索结果中高亮部分的 HTML 标签
|
# {{< version 0.2.1 >}} 搜索结果中高亮部分的 HTML 标签
|
||||||
highlightTag = "em"
|
highlightTag = "em"
|
||||||
|
# {{< version 0.2.4 >}} 是否在搜索索引中使用基于 baseURL 的绝对路径
|
||||||
|
absoluteURL = false
|
||||||
[params.search.algolia]
|
[params.search.algolia]
|
||||||
index = ""
|
index = ""
|
||||||
appID = ""
|
appID = ""
|
||||||
|
|||||||
@@ -1,41 +1,46 @@
|
|||||||
{{- $index := slice -}}
|
{{- if .Site.Params.search -}}
|
||||||
{{- $pages := .Site.RegularPages -}}
|
{{- $index := slice -}}
|
||||||
{{- if .Site.Params.page.hiddenFromSearch -}}
|
{{- $pages := .Site.RegularPages -}}
|
||||||
{{- $pages = where $pages "Params.hiddenfromsearch" false -}}
|
{{- if .Site.Params.page.hiddenFromSearch -}}
|
||||||
{{- else -}}
|
{{- $pages = where $pages "Params.hiddenfromsearch" false -}}
|
||||||
{{- $pages = where $pages "Params.hiddenfromsearch" "!=" true -}}
|
{{- else -}}
|
||||||
{{- end -}}
|
{{- $pages = where $pages "Params.hiddenfromsearch" "!=" true -}}
|
||||||
{{- range $pages -}}
|
|
||||||
{{- $uri := .RelPermalink -}}
|
|
||||||
{{- $meta := dict "uri" $uri "title" .Title "tags" .Params.tags "categories" .Params.categories -}}
|
|
||||||
{{- $meta = .PublishDate.Format ($.Site.Params.dateFormat | default "2006-01-02") | dict "date" | merge $meta -}}
|
|
||||||
{{- with .Description -}}
|
|
||||||
{{- $index = $index | append (dict "content" . "objectID" $uri | merge $meta) -}}
|
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- $params := .Params | merge $.Site.Params.page -}}
|
{{- range $pages -}}
|
||||||
{{/* Extended Markdown syntax */}}
|
{{- $uri := .RelPermalink -}}
|
||||||
{{- $content := dict "content" .Content "ruby" $params.ruby "fraction" $params.fraction "fontawesome" $params.fontawesome | partial "function/content.html" -}}
|
{{- if $.Site.Params.search.absoluteURL -}}
|
||||||
{{/* Remove line number for code */}}
|
{{- $uri = .Permalink -}}
|
||||||
{{- $content = $content | replaceRE `<span class="lnt?"> *\d*\n?</span>` "" -}}
|
|
||||||
{{- range $i, $contenti := split $content "<h2 id=" -}}
|
|
||||||
{{- if gt $i 0 -}}
|
|
||||||
{{- $contenti = printf "<h2 id=%s" $contenti -}}
|
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- range $j, $contentj := split $contenti "<h3 id=" -}}
|
{{- $meta := dict "uri" $uri "title" .Title "tags" .Params.tags "categories" .Params.categories -}}
|
||||||
{{- if gt $j 0 -}}
|
{{- $meta = .PublishDate.Format ($.Site.Params.dateFormat | default "2006-01-02") | dict "date" | merge $meta -}}
|
||||||
{{- $contentj = printf "<h3 id=%s" $contentj -}}
|
{{- with .Description -}}
|
||||||
|
{{- $index = $index | append (dict "content" . "objectID" $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=%s" $contenti -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{/* Plainify, unescape and remove (\n, \t) */}}
|
{{- range $j, $contentj := split $contenti "<h3 id=" -}}
|
||||||
{{- $contentj = $contentj | plainify | htmlUnescape | replaceRE `[\n\t ]+` " " -}}
|
{{- if gt $j 0 -}}
|
||||||
{{- if gt $.Site.Params.search.contentLength 0 -}}
|
{{- $contentj = printf "<h3 id=%s" $contentj -}}
|
||||||
{{- $contentj = substr $contentj 0 $.Site.Params.search.contentLength -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{/* Plainify, unescape and remove (\n, \t) */}}
|
||||||
{{- if $contentj | and (ne $contentj " ") -}}
|
{{- $contentj = $contentj | plainify | htmlUnescape | replaceRE `[\n\t ]+` " " -}}
|
||||||
{{- $one := printf "%s:%d:%d" $uri $i $j | dict "content" $contentj "objectID" | merge $meta -}}
|
{{- if gt $.Site.Params.search.contentLength 0 -}}
|
||||||
{{- $index = $index | append $one -}}
|
{{- $contentj = substr $contentj 0 $.Site.Params.search.contentLength -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- if $contentj | and (ne $contentj " ") -}}
|
||||||
|
{{- $one := printf "%s:%d:%d" $uri $i $j | dict "content" $contentj "objectID" | merge $meta -}}
|
||||||
|
{{- $index = $index | append $one -}}
|
||||||
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
|
||||||
|
|
||||||
{{- $index | jsonify | safeJS -}}
|
{{- $index | jsonify | safeJS -}}
|
||||||
|
{{- end -}}
|
||||||
|
|||||||
Reference in New Issue
Block a user