mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 07:47:54 +00:00
search: remove JSON outputformat for search index #846
This commit is contained in:
parent
e8a0d000c3
commit
bd3a4030fb
8 changed files with 13 additions and 62 deletions
|
@ -32,8 +32,9 @@ title = "Hugo Relearn Theme"
|
||||||
summaryLength = 10
|
summaryLength = 10
|
||||||
|
|
||||||
[outputs]
|
[outputs]
|
||||||
# add `json` to the home to support Lunr search; This is a mandatory setting
|
# add `search` to the home to support Lunr search; This is a mandatory setting
|
||||||
# for the search functionality
|
# for the side wide search functionality
|
||||||
|
# add `searchpage` to the home to create a dedicated searchpage
|
||||||
# add `print` to home, section and page to activate the feature to print whole
|
# add `print` to home, section and page to activate the feature to print whole
|
||||||
# chapters
|
# chapters
|
||||||
home = ["html", "rss", "print", "search", "searchpage"]
|
home = ["html", "rss", "print", "search", "searchpage"]
|
||||||
|
|
|
@ -64,11 +64,7 @@ If not already present, add the following lines in your `hugo.toml` file.
|
||||||
home = ["html", "rss", "search"]
|
home = ["html", "rss", "search"]
|
||||||
{{< /multiconfig >}}
|
{{< /multiconfig >}}
|
||||||
|
|
||||||
This will generate a search index file at the root of your public folder ready to be consumed by the Lunr search library. Note that the `search` outputformat was named `json` in previous releases but was implemented differently. Although `json` still works, it is now deprecated.
|
This will generate a search index file at the root of your public folder ready to be consumed by the Lunr search library.
|
||||||
|
|
||||||
{{% notice note %}}
|
|
||||||
If you want to use the search feature from the file system, migrating from an older installation of the theme, make sure to change your outputformat for the homepage from the now deprecated `json` to `search` [as seen below](#activate-search).
|
|
||||||
{{% /notice %}}
|
|
||||||
|
|
||||||
### Activate dedicated search page
|
### Activate dedicated search page
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,10 @@ This document shows you what's new in the latest release and flags it with one o
|
||||||
--CODE-theme: monokai;
|
--CODE-theme: monokai;
|
||||||
````
|
````
|
||||||
|
|
||||||
|
- {{% badge style="warning" title=" " %}}Breaking{{% /badge %}} Search support for the deprecated outputformat `json` was removed.
|
||||||
|
|
||||||
|
Change it to `search` for the homepage in your `hugo.toml`. See the docs for [detailed configuration](basics/customization#activate-search).
|
||||||
|
|
||||||
- {{% badge style="warning" title=" " %}}Breaking{{% /badge %}} The parameter `description` in your `hugo.toml` will now be ignored.
|
- {{% badge style="warning" title=" " %}}Breaking{{% /badge %}} The parameter `description` in your `hugo.toml` will now be ignored.
|
||||||
|
|
||||||
With the newly introduced unified handling of descriptions throughout the theme, the only place the old parameter would have been used was your home page.
|
With the newly introduced unified handling of descriptions throughout the theme, the only place the old parameter would have been used was your home page.
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
{{- partialCached "page-meta.hugo" . .RelPermalink }}
|
|
||||||
{{- $pages := slice }}
|
|
||||||
{{- range .Site.Pages }}
|
|
||||||
{{- if and .Title .RelPermalink (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableSearchHiddenPages true) ) }}
|
|
||||||
{{- $pages = $pages | append (dict
|
|
||||||
"uri" (partial "relLangPrettyUglyURL.hugo" (dict "to" .))
|
|
||||||
"title" (partial "pageHelper/title.hugo" (dict "page" .))
|
|
||||||
"tags" .Params.tags
|
|
||||||
"breadcrumb" (trim ((partial "breadcrumbs.html" (dict "page" . "dirOnly" true)) | plainify | htmlUnescape) "\n\r\t ")
|
|
||||||
"description" (or .Description .Summary)
|
|
||||||
"content" (.Plain | htmlUnescape)
|
|
||||||
) }}
|
|
||||||
{{- end }}
|
|
||||||
{{- end -}}
|
|
||||||
{{- $pages | jsonify (dict "indent" " ") }}
|
|
|
@ -38,21 +38,12 @@
|
||||||
{{ (printf $link (partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true "basename" $basename)) .Rel .MediaType.Type ($title | htmlEscape)) | safeHTML }}
|
{{ (printf $link (partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true "basename" $basename)) .Rel .MediaType.Type ($title | htmlEscape)) | safeHTML }}
|
||||||
{{- else if eq $outputFormat "searchpage" }}
|
{{- else if eq $outputFormat "searchpage" }}
|
||||||
{{- else if eq .Name "searchpage" }}
|
{{- else if eq .Name "searchpage" }}
|
||||||
{{- else if and (ne .Name "json") (ne .Name "search") }}
|
{{- else if ne .Name "search" }}
|
||||||
{{ (printf $link (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) .Rel .MediaType.Type ($title | htmlEscape)) | safeHTML }}
|
{{ (printf $link (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) .Rel .MediaType.Type ($title | htmlEscape)) | safeHTML }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
{{- if and (ne .Site.Params.disableSeoHiddenPages true) (ne .Site.Params.disableSearchHiddenPages true) }}
|
|
||||||
{{- range .AlternativeOutputFormats }}
|
|
||||||
{{- if eq .Name "searchpage" }}
|
|
||||||
{{- else if eq .Name "json" }}
|
|
||||||
{{ (printf $link (.Permalink | relURL) .Rel .MediaType.Type ($title | htmlEscape)) | safeHTML }}
|
|
||||||
{{- end }}
|
|
||||||
{{- end }}
|
|
||||||
{{- end }}
|
|
||||||
|
|
||||||
{{- partialCached "favicon.html" . }}
|
{{- partialCached "favicon.html" . }}
|
||||||
{{- partial "stylesheet.html" (dict "page" . "outputFormat" $outputFormat) }}
|
{{- partial "stylesheet.html" (dict "page" . "outputFormat" $outputFormat) }}
|
||||||
{{- partial "dependencies.html" (dict "page" . "location" "header" "outputFormat" $outputFormat) }}
|
{{- partial "dependencies.html" (dict "page" . "location" "header" "outputFormat" $outputFormat) }}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
{{- $link := "" }}
|
{{- $link := "" }}
|
||||||
{{- if or (.Site.Home.OutputFormats.Get "json") (.Site.Home.OutputFormats.Get "search") }}
|
{{- with .Site.Home.OutputFormats.Get "json" }}
|
||||||
|
{{- warnf "UNSUPPORTED usage of 'json' output format found, use 'search' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration#600" }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Site.Home.OutputFormats.Get "search" }}
|
||||||
{{- with .Site.Home.OutputFormats.Get "searchpage" }}
|
{{- with .Site.Home.OutputFormats.Get "searchpage" }}
|
||||||
{{- $link = partial "relLangPrettyUglyURL.hugo" (dict "to" .) }}
|
{{- $link = partial "relLangPrettyUglyURL.hugo" (dict "to" .) }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
|
@ -30,10 +30,6 @@
|
||||||
window.relearn.relBasePath='{{ partial "relBasePath.hugo" $page | safeJS }}';
|
window.relearn.relBasePath='{{ partial "relBasePath.hugo" $page | safeJS }}';
|
||||||
window.relearn.relBaseUri='{{ partial "relBaseUri.hugo" $page | safeJS }}';
|
window.relearn.relBaseUri='{{ partial "relBaseUri.hugo" $page | safeJS }}';
|
||||||
window.relearn.absBaseUri='{{ replaceRE "/*$" "" .Site.BaseURL | safeJS }}';
|
window.relearn.absBaseUri='{{ replaceRE "/*$" "" .Site.BaseURL | safeJS }}';
|
||||||
{{- with .Site.Home.OutputFormats.Get "json" }}
|
|
||||||
{{- warnf "DEPRECATED usage of 'json' output format found, use 'search' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/customization#activate-search" }}
|
|
||||||
window.index_json_url={{ "index.json" | relLangURL }};
|
|
||||||
{{- end }}
|
|
||||||
{{- with .Site.Home.OutputFormats.Get "search" }}
|
{{- with .Site.Home.OutputFormats.Get "search" }}
|
||||||
window.index_js_url={{ "index.search.js" | relLangURL }};
|
window.index_js_url={{ "index.search.js" | relLangURL }};
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
|
@ -109,30 +109,6 @@ if( input ){
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function initLunrJson() {
|
|
||||||
// old way to load the search index via XHR;
|
|
||||||
// this does not work if pages are served via
|
|
||||||
// file:// protocol; this is only left for
|
|
||||||
// backward compatiblity if the user did not
|
|
||||||
// define the `search` output format for the homepage
|
|
||||||
if( window.index_json_url && !window.index_js_url ){
|
|
||||||
xhr = new XMLHttpRequest;
|
|
||||||
xhr.onreadystatechange = function(){
|
|
||||||
if( xhr.readyState == 4 ){
|
|
||||||
if( xhr.status == 200 ){
|
|
||||||
initLunrIndex( JSON.parse( xhr.responseText ) );
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
var err = xhr.status;
|
|
||||||
console.error( 'Error getting Hugo index file: ', err );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
xhr.open( 'GET', index_json_url );
|
|
||||||
xhr.send();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function initLunrJs() {
|
function initLunrJs() {
|
||||||
// new way to load our search index
|
// new way to load our search index
|
||||||
if( window.index_js_url ){
|
if( window.index_js_url ){
|
||||||
|
@ -257,7 +233,6 @@ function searchDetail( value ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initLunrJson();
|
|
||||||
initLunrJs();
|
initLunrJs();
|
||||||
|
|
||||||
function startSearch(){
|
function startSearch(){
|
||||||
|
|
Loading…
Reference in a new issue