From bd3a4030fbe14f73a321372ad7d922d658e805be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Fri, 26 Apr 2024 23:35:56 +0200 Subject: [PATCH] search: remove JSON outputformat for search index #846 --- exampleSite/config/_default/hugo.toml | 5 ++-- .../content/basics/customization/_index.en.md | 6 +---- .../content/basics/migration/_index.en.md | 4 +++ layouts/_default/index.json | 15 ----------- layouts/partials/header.html | 11 +------- layouts/partials/search.html | 5 +++- layouts/partials/stylesheet.html | 4 --- static/js/search.js | 25 ------------------- 8 files changed, 13 insertions(+), 62 deletions(-) delete mode 100644 layouts/_default/index.json diff --git a/exampleSite/config/_default/hugo.toml b/exampleSite/config/_default/hugo.toml index 855a2ceee8..3dbd8b1065 100644 --- a/exampleSite/config/_default/hugo.toml +++ b/exampleSite/config/_default/hugo.toml @@ -32,8 +32,9 @@ title = "Hugo Relearn Theme" summaryLength = 10 [outputs] - # add `json` to the home to support Lunr search; This is a mandatory setting - # for the search functionality + # add `search` to the home to support Lunr search; This is a mandatory setting + # 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 # chapters home = ["html", "rss", "print", "search", "searchpage"] diff --git a/exampleSite/content/basics/customization/_index.en.md b/exampleSite/content/basics/customization/_index.en.md index 4ae7a9df65..1e991cb67f 100644 --- a/exampleSite/content/basics/customization/_index.en.md +++ b/exampleSite/content/basics/customization/_index.en.md @@ -64,11 +64,7 @@ If not already present, add the following lines in your `hugo.toml` file. home = ["html", "rss", "search"] {{< /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. - -{{% 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 %}} +This will generate a search index file at the root of your public folder ready to be consumed by the Lunr search library. ### Activate dedicated search page diff --git a/exampleSite/content/basics/migration/_index.en.md b/exampleSite/content/basics/migration/_index.en.md index 9955e8f25e..dc52d5dd96 100644 --- a/exampleSite/content/basics/migration/_index.en.md +++ b/exampleSite/content/basics/migration/_index.en.md @@ -32,6 +32,10 @@ This document shows you what's new in the latest release and flags it with one o --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. 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. diff --git a/layouts/_default/index.json b/layouts/_default/index.json deleted file mode 100644 index 652ee6f999..0000000000 --- a/layouts/_default/index.json +++ /dev/null @@ -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" " ") }} diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 8556486454..06aee77b84 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -38,21 +38,12 @@ {{ (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 .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 }} {{- 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" . }} {{- partial "stylesheet.html" (dict "page" . "outputFormat" $outputFormat) }} {{- partial "dependencies.html" (dict "page" . "location" "header" "outputFormat" $outputFormat) }} diff --git a/layouts/partials/search.html b/layouts/partials/search.html index 17960498e4..d12ba72b79 100644 --- a/layouts/partials/search.html +++ b/layouts/partials/search.html @@ -1,5 +1,8 @@ {{- $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" }} {{- $link = partial "relLangPrettyUglyURL.hugo" (dict "to" .) }} {{- end }} diff --git a/layouts/partials/stylesheet.html b/layouts/partials/stylesheet.html index b7c344a791..2f5b9b633b 100644 --- a/layouts/partials/stylesheet.html +++ b/layouts/partials/stylesheet.html @@ -30,10 +30,6 @@ window.relearn.relBasePath='{{ partial "relBasePath.hugo" $page | safeJS }}'; window.relearn.relBaseUri='{{ partial "relBaseUri.hugo" $page | 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" }} window.index_js_url={{ "index.search.js" | relLangURL }}; {{- end }} diff --git a/static/js/search.js b/static/js/search.js index df46649716..f347b387b8 100644 --- a/static/js/search.js +++ b/static/js/search.js @@ -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() { // new way to load our search index if( window.index_js_url ){ @@ -257,7 +233,6 @@ function searchDetail( value ) { } } -initLunrJson(); initLunrJs(); function startSearch(){