theme: compatiblity for output format with Hugo 0.123 #771

This commit is contained in:
Sören Weber 2024-02-10 23:22:35 +01:00
parent eaabbfd6ef
commit 4bc5529bc8
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
11 changed files with 41 additions and 39 deletions

View file

@ -34,13 +34,13 @@ defaultContentLanguage = "en"
title = "Hugo Relearn Theme"
[outputs]
# add JSON to the home to support Lunr search; This is a mandatory setting
# add `json` to the home to support Lunr search; This is a mandatory setting
# for the search functionality
# 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
home = ["HTML", "RSS", "PRINT", "SEARCH", "SEARCHPAGE"]
section = ["HTML", "RSS", "PRINT"]
page = ["HTML", "RSS", "PRINT"]
home = ["html", "rss", "print", "search", "searchpage"]
section = ["html", "rss", "print"]
page = ["html", "rss", "print"]
[markup]
[markup.highlight]

View file

@ -31,7 +31,7 @@ The theme will append an additional `index.html` to all page bundle links by def
````
{{% notice note %}}
If you want to use the search feature from the file system using 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).
If you want to use the search feature from the file system using 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 search
@ -40,18 +40,18 @@ If not already present, add the following lines in your `hugo.toml` file.
```toml
[outputs]
home = ["HTML", "RSS", "SEARCH"]
home = ["html", "rss", "search"]
```
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. Note that the `search` outputformat was named `json` in previous releases but was implemented differently. Although `json` still works, it is now deprecated.
### Activate dedicated search page
You can add a dedicated search page for your page by adding the `SEARCHPAGE` outputformat to your home page by adding the following lines in your `hugo.toml` file. This will cause Hugo to generate a new file `http://example.com/mysite/search.html`.
You can add a dedicated search page for your page by adding the `searchpage` outputformat to your home page by adding the following lines in your `hugo.toml` file. This will cause Hugo to generate a new file `http://example.com/mysite/search.html`.
```toml
[outputs]
home = ["HTML", "RSS", "SEARCH", "SEARCHPAGE"]
home = ["html", "rss", "search", "searchpage"]
```
You can access this page by either clicking on the magnifier glass or by typing some search term and pressing `ENTER` inside of the menu's search box .
@ -66,13 +66,13 @@ To make sure, there is no duplicate content for any given URL of your project, r
## Activate print support
You can activate print support to add the capability to print whole chapters or even the complete site. Just add the `PRINT` output format to your home, section and page in your `hugo.toml` as seen below:
You can activate print support to add the capability to print whole chapters or even the complete site. Just add the `print` output format to your home, section and page in your `hugo.toml` as seen below:
```toml
[outputs]
home = ["HTML", "RSS", "PRINT", "SEARCH"]
section = ["HTML", "RSS", "PRINT"]
page = ["HTML", "RSS", "PRINT"]
home = ["html", "rss", "print", "search"]
section = ["html", "rss", "print"]
page = ["html", "rss", "print"]
```
This will add a little printer icon in the top bar. It will switch the page to print preview when clicked. You can then send this page to the printer by using your browser's usual print functionality.
@ -80,7 +80,7 @@ This will add a little printer icon in the top bar. It will switch the page to p
{{% notice note %}}
The resulting URL will not be [configured ugly](https://gohugo.io/templates/output-formats/#configure-output-formats) in terms of [Hugo's URL handling](https://gohugo.io/content-management/urls/#ugly-urls) even if you've set `uglyURLs=true` in your `hugo.toml`. This is due to the fact that for one mime type only one suffix can be configured.
Nevertheless, if you're unhappy with the resulting URLs you can manually redefine `outputFormats.PRINT` in your own `hugo.toml` to your liking.
Nevertheless, if you're unhappy with the resulting URLs you can manually redefine `outputFormats.print` in your own `hugo.toml` to your liking.
{{% /notice %}}
## Home Button Configuration

View file

@ -42,7 +42,7 @@ theme = "hugo-theme-relearn"
# For search functionality
[outputs]
home = [ "HTML", "RSS", "SEARCH"]
home = [ "html", "rss", "search"]
```
## Create your first chapter page

View file

@ -46,6 +46,8 @@ This document shows you what's new in the latest release and flags it with one o
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} Restored compatibility with Hugo versions {{% badge color="fuchsia" icon="fab fa-hackerrank" title=" " %}}0.121.0{{% /badge %}} or higher for the [`highlight` shortcode](shortcodes/highlight). This does not change the minimum required Hugo version.
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} Restored compatibility with Hugo versions {{% badge color="fuchsia" icon="fab fa-hackerrank" title=" " %}}0.123.0{{% /badge %}} or higher for theme specific [output formats](basics/customization). This does not change the minimum required Hugo version.
---
## 5.23.0 (2023-11-03) {#5230}
@ -422,7 +424,7 @@ This document shows you what's new in the latest release and flags it with one o
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} This release introduces an additional dedicated search page. On this page, displayed search results have more space making it easier scanning thru large number of results.
To activate this feature, you need to [configure it](basics/customization#activate-dedicated-search-page) in your `hugo.toml` as a new outputformat `SEARCHPAGE` for the home page. If you don't configure it, no dedicated search page will be accessible and the theme works as before.
To activate this feature, you need to [configure it](basics/customization#activate-dedicated-search-page) in your `hugo.toml` as a new outputformat `searchpage` for the home page. If you don't configure it, no dedicated search page will be accessible and the theme works as before.
You can access the search page by either clicking on the magnifier glass or pressing enter inside of the search box.
@ -460,7 +462,7 @@ This document shows you what's new in the latest release and flags it with one o
- {{% badge style="note" title=" " %}}Change{{% /badge %}} [With the proper settings](basics/customization#serving-your-page-from-the-filesystem) in your `hugo.toml` your page is now servable from the local file system using `file://` URLs.
Please note that the searchbox will only work for this if you reconfigure your outputformat for the homepage in your `hugo.toml` from `JSON` to `SEARCH`. The now deprecated `JSON` outputformat still works as before, so there is no need to reconfigure your installation if it is only served from `http://` or `https://`.
Please note that the searchbox will only work for this if you reconfigure your outputformat for the homepage in your `hugo.toml` from `json` to `search`. The now deprecated `json` outputformat still works as before, so there is no need to reconfigure your installation if it is only served from `http://` or `https://`.
- {{% badge style="note" title=" " %}}Change{{% /badge %}} The [`button` shortcode](shortcodes/button) has a new parameter `target` to set the destination frame/window for the URL to open. If not given, it defaults to a new window/tab for external URLs or is not set at all for internal URLs. Previously even internal URLs where opened in a new window/tab.
@ -494,12 +496,12 @@ This document shows you what's new in the latest release and flags it with one o
- {{% badge style="note" title=" " %}}Change{{% /badge %}} Because the print preview URLs were non deterministic for normal pages in comparison to page bundles, this is now changed. Each print preview is now accessible by adding a `index.print.html` to the default URL.
You can revert this behavior by overwriting the PRINT output format setting in your `hugo.toml`to:
You can revert this behavior by overwriting the `print` output format setting in your `hugo.toml`to:
````toml
[outputFormats]
[outputFormats.PRINT]
name= "PRINT"
[outputFormats.print]
name= "print"
baseName = "index"
path = "_print"
isHTML = true

View file

@ -7,24 +7,24 @@
suffixes = ["js"]
[outputFormats]
[outputFormats.PRINT]
name= "PRINT"
[outputFormats.print]
name= "print"
baseName = "index.print"
isHTML = true
mediaType = 'text/html'
permalinkable = false
noUgly = true
[outputFormats.SEARCH]
name= "SEARCH"
[outputFormats.search]
name= "search"
baseName = "index.search"
isPlainText = true
mediaType = 'text/javascript'
permalinkable = false
noUgly = true
[outputFormats.SEARCHPAGE]
name= "SEARCHPAGE"
[outputFormats.searchpage]
name= "searchpage"
baseName = "search"
isHTML = true
mediaType = 'text/html'

View file

@ -34,7 +34,7 @@
<webMaster>{{ . }}{{ with $authorName }} ({{ . }}){{ end }}</webMaster>{{ end }}{{ with .Site.Copyright }}
<copyright>{{ . }}</copyright>{{ end }}{{ if not .Date.IsZero }}
<lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
{{- with .OutputFormats.Get "RSS" }}
{{- with .OutputFormats.Get "rss" }}
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" ( partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true)) .MediaType | safeHTML }}
{{- end -}}
{{- range $pages }}

View file

@ -49,8 +49,8 @@
{{- if eq .Rel "canonical" }}
{{ (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 eq .Name "searchpage" }}
{{- else if and (ne .Name "json") (ne .Name "search") }}
{{ (printf $link (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) .Rel .MediaType.Type ($title | htmlEscape)) | safeHTML }}
{{- end }}
{{- end }}
@ -58,8 +58,8 @@
{{- if and (ne .Site.Params.disableSeoHiddenPages true) (ne .Site.Params.disableSearchHiddenPages true) }}
{{- range .AlternativeOutputFormats }}
{{- if eq .Name "SEARCHPAGE" }}
{{- else if eq .Name "JSON" }}
{{- if eq .Name "searchpage" }}
{{- else if eq .Name "json" }}
{{ (printf $link (.Permalink | relURL) .Rel .MediaType.Type ($title | htmlEscape)) | safeHTML }}
{{- end }}
{{- end }}

View file

@ -1,6 +1,6 @@
{{- $link := "" }}
{{- if or (.Site.Home.OutputFormats.Get "JSON") (.Site.Home.OutputFormats.Get "SEARCH") }}
{{- with .Site.Home.OutputFormats.Get "SEARCHPAGE" }}
{{- if or (.Site.Home.OutputFormats.Get "json") (.Site.Home.OutputFormats.Get "search") }}
{{- with .Site.Home.OutputFormats.Get "searchpage" }}
{{- $link = partial "relLangPrettyUglyURL.hugo" (dict "to" .) }}
{{- end }}
{{- end }}

View file

@ -31,11 +31,11 @@
<script>
{{ "// hack to let hugo tell us how to get to the root when using relativeURLs, it needs to be called *url= for it to do its magic:" | safeJS }}
{{ "// https://github.com/gohugoio/hugo/blob/145b3fcce35fbac25c7033c91c1b7ae6d1179da8/transform/urlreplacers/absurlreplacer.go#L72" | safeJS }}
{{- with .Site.Home.OutputFormats.Get "JSON" }}
{{- warnf "%q: DEPRECATED usage of 'JSON' output format found, use 'SEARCH' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/customization#activate-search" $page.File.Filename }}
{{- with .Site.Home.OutputFormats.Get "json" }}
{{- warnf "%q: DEPRECATED usage of 'json' output format found, use 'search' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/customization#activate-search" $page.File.Filename }}
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 }};
{{- end }}
var root_url="/";

View file

@ -4,7 +4,7 @@
{{- with .page }}
{{- $format := partial "get-format.hugo" . }}
{{- $outputFormat := partial "output-format.hugo" (dict "page" . "format" $format) }}
{{- $printFormat := .OutputFormats.Get "PRINT" }}
{{- $printFormat := .OutputFormats.Get "print" }}
{{- if and (eq $outputFormat "html") $printFormat }}
{{- partial "topbar/func/button.html" (dict
"page" .

View file

@ -114,7 +114,7 @@ function initLunrJson() {
// 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
// define the `search` output format for the homepage
if( window.index_json_url && !window.index_js_url ){
xhr = new XMLHttpRequest;
xhr.onreadystatechange = function(){