rework search integration (#262)

This commit is contained in:
Robert Kaussow 2022-01-06 22:52:22 +01:00 committed by GitHub
parent 00334dbfbf
commit bbfc75ecb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 8 additions and 64 deletions

View File

@ -1,5 +1,5 @@
{{- $searchDataFile := printf "%s.searchdata.json" .Language.Lang -}} {{- $searchDataFile := printf "search/%s.data.json" .Language.Lang -}}
{{- $searchData := resources.Get "search/searchdata.json" | resources.ExecuteAsTemplate $searchDataFile . | resources.Minify -}} {{- $searchData := resources.Get "search/data.json" | resources.ExecuteAsTemplate $searchDataFile . | resources.Minify -}}
{ {
"dataFile": {{ $searchData.RelPermalink | jsonify }}, "dataFile": {{ $searchData.RelPermalink | jsonify }},
"indexConfig": {{ .Site.Params.GeekdocSearchConfig | jsonify }}, "indexConfig": {{ .Site.Params.GeekdocSearchConfig | jsonify }},

View File

@ -23,22 +23,9 @@ markup:
taxonomies: taxonomies:
tag: tags tag: tags
outputFormats:
Search:
name: "Search"
mediaType: "application/json"
# generated file: <baseName>.<mediaType."application/feed+json".suffixes[0]> = feed.json
baseName: "searchconfig"
isPlainText: false
rel: "alternate"
isHTML: false
noUgly: true
permalinkable: false
outputs: outputs:
home: home:
- HTML - HTML
- SEARCH
page: page:
- HTML - HTML
section: section:

View File

@ -32,19 +32,6 @@ enableRobotsTXT = true
startLevel = 1 startLevel = 1
endLevel = 9 endLevel = 9
[outputFormats.Search]
name = "Search"
mediaType = "application/json"
baseName = "searchconfig"
isPlainText = false
rel = "alternate"
isHTML = false
noUgly = true
permalinkable = false
[outputs]
home = [ "HTML", "SEARCH" ]
[taxonomies] [taxonomies]
tag = "tags" tag = "tags"
@ -83,8 +70,7 @@ home = [ "HTML", "SEARCH" ]
# You can also specify this parameter per page in front matter. # You can also specify this parameter per page in front matter.
geekdocEditPath = "edit/main/exampleSite/content" geekdocEditPath = "edit/main/exampleSite/content"
# (Optional, default true) Enables search function with flexsearch. To use the search you # (Optional, default true) Enables search function with flexsearch.
# have to ensure `outputFormats` and `outputs` are properly configured as well (see below).
# Index is built on the fly and might slow down your website. # Index is built on the fly and might slow down your website.
geekdocSearch = false geekdocSearch = false
@ -162,23 +148,6 @@ markup:
taxonomies: taxonomies:
tag: tags tag: tags
outputFormats:
Search:
name: "Search"
mediaType: "application/json"
# generated file: <baseName>.<mediaType."application/feed+json".suffixes[0]> = feed.json
baseName: "searchconfig"
isPlainText: false
rel: "alternate"
isHTML: false
noUgly: true
permalinkable: false
outputs:
home:
- HTML
- SEARCH
params: params:
# (Optional, default 6) Set how many table of contents levels to be showed on page. # (Optional, default 6) Set how many table of contents levels to be showed on page.
# Use false to hide ToC, note that 0 will default to 6 (https://gohugo.io/functions/default/) # Use false to hide ToC, note that 0 will default to 6 (https://gohugo.io/functions/default/)
@ -214,8 +183,7 @@ params:
# You can also specify this parameter per page in front matter. # You can also specify this parameter per page in front matter.
geekdocEditPath: edit/main/exampleSite/content geekdocEditPath: edit/main/exampleSite/content
# (Optional, default true) Enables search function with flexsearch. To use the search you # (Optional, default true) Enables search function with flexsearch.
# have to ensure `outputFormats` and `outputs` are properly configured as well (see below).
# Index is built on the fly and might slow down your website. # Index is built on the fly and might slow down your website.
geekdocSearch: false geekdocSearch: false

View File

@ -69,19 +69,6 @@ To prepare your new site environment just a few steps are required:
[taxonomies] [taxonomies]
tag = "tags" tag = "tags"
[outputFormats.Search]
name = "Search"
mediaType = "application/json"
baseName = "searchconfig"
isPlainText = false
rel = "alternate"
isHTML = false
noUgly = true
permalinkable = false
[outputs]
home = [ "HTML", "SEARCH" ]
``` ```
5. Test your site. 5. Test your site.

View File

@ -1,3 +1,5 @@
{{ if default true .Site.Params.GeekdocSearch }} {{ if default true .Site.Params.GeekdocSearch }}
<script defer src="{{ index (index .Site.Data.assets "search.js") "src" | relURL }}"></script> <script defer src="{{ index (index .Site.Data.assets "search.js") "src" | relURL }}"></script>
{{- $searchConfig := resources.Get "search/config.json" | resources.ExecuteAsTemplate "search/config.json" . | resources.Minify -}}
<!-- {{ $searchConfig.Permalink }} -->
{{ end }} {{ end }}

View File

@ -24,7 +24,7 @@ document.addEventListener("DOMContentLoaded", function (event) {
additionalProperties: false additionalProperties: false
} }
getJson("/searchconfig.json", function (searchConfig) { getJson("/search/config.min.json", function (searchConfig) {
const configValidate = ajv.compile(configSchema) const configValidate = ajv.compile(configSchema)
const valid = configValidate(searchConfig) const valid = configValidate(searchConfig)