From b9efb82a1ca56f5d0c5dd5c5fb546c8d90e9daf6 Mon Sep 17 00:00:00 2001 From: Junnygram Date: Fri, 3 Apr 2026 05:40:33 +0100 Subject: [PATCH] [Docs] Resolve .Site.AllPages deprecation Signed-off-by: Junnygram --- assets/json/offline-search-index.json | 21 +++++++++++++++++++++ hugo.yaml | 2 +- layouts/_default/sitemap.xml | 22 ++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 assets/json/offline-search-index.json create mode 100644 layouts/_default/sitemap.xml diff --git a/assets/json/offline-search-index.json b/assets/json/offline-search-index.json new file mode 100644 index 0000000..3481fd8 --- /dev/null +++ b/assets/json/offline-search-index.json @@ -0,0 +1,21 @@ +{{- $.Scratch.Add "offline-search-index" slice -}} +{{- range hugo.Sites -}} +{{- range where .Pages ".Params.exclude_search" "!=" true -}} +{{- /* We have to apply `htmlUnescape` again after `truncate` because `truncate` + applies `html.EscapeString` if the argument is not HTML. */ -}} +{{- /* Individual taxonomies can be added in the next line by adding '"taxonomy-name" (.Params.taxonomy-name | default "")' to the dict (as seen for categories and tags). */ -}} +{{- $.Scratch.Add +"offline-search-index" +(dict +"ref" .RelPermalink +"title" .Title +"categories" (.Params.categories | default "") +"tags" (.Params.tags | default "") +"description" (.Description | default "") +"body" (.Plain | htmlUnescape) +"excerpt" ((.Description | default .Plain) | htmlUnescape | truncate (.Site.Params.offlineSearchSummaryLength | default 70) | htmlUnescape) +) +-}} +{{- end -}} +{{- end -}} +{{- $.Scratch.Get "offline-search-index" | jsonify -}} diff --git a/hugo.yaml b/hugo.yaml index 884bae5..7d2b71c 100644 --- a/hugo.yaml +++ b/hugo.yaml @@ -11,7 +11,7 @@ markup: module: hugoVersion: extended: true - min: 0.146.0 + min: 0.156.0 imports: # used to source the base theme for academy. diff --git a/layouts/_default/sitemap.xml b/layouts/_default/sitemap.xml new file mode 100644 index 0000000..6153b54 --- /dev/null +++ b/layouts/_default/sitemap.xml @@ -0,0 +1,22 @@ +{{ printf "" | safeHTML }} + + {{ range hugo.Sites }} + {{ range .Pages }} + {{- if and (not .Params.sitemap_exclude) (not .Draft) }} + + {{ .Permalink }} + {{- if not .Lastmod.IsZero }} + {{ .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML }} + {{- end }} + {{- with .Sitemap.ChangeFreq }} + {{ . }} + {{- end }} + {{- if ge .Sitemap.Priority 0.0 }} + {{ .Sitemap.Priority }} + {{- end }} + + {{- end }} + {{ end }} + {{ end }} +