From 963d005d7af57b082ed945b4b83b5f9a4c005b71 Mon Sep 17 00:00:00 2001 From: Mark Dumay <61946753+markdumay@users.noreply.github.com> Date: Fri, 17 Jul 2026 20:08:28 +0200 Subject: [PATCH] fix: publish the search index on Hugo < 0.164 (avoid the PostProcess/Defer clash) On Hugo < 0.164 a page that uses resources.PostProcess silently prevents that page's templates.Defer blocks from executing. Hinode's production stylesheet always uses resources.PostProcess (it is how css.PostCSS is deferred so PurgeCSS reads a complete hugo_stats.json), so the deferred search index never published and its raw __hdeferred placeholder token leaked into the navbar search box. Version-gate the publisher: keep templates.Defer on Hugo >= 0.164 (no serial render), and on older Hugo publish the index eagerly instead, guarded to run once per language via site.Store. Correct on both paths at the cost of the serial-render stall on old Hugo that Defer was introduced to avoid. Verified on the exampleSite across Hugo 0.146.7 / 0.147.6 / 0.161.1 / 0.164.0: no placeholder leak on any version; index published on all; the eager (0.161) and deferred (0.164) indexes are byte-identical (550,561 B). --- layouts/_partials/assets/search-index.html | 37 +++++++++++++++++----- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/layouts/_partials/assets/search-index.html b/layouts/_partials/assets/search-index.html index 0819941..c392536 100644 --- a/layouts/_partials/assets/search-index.html +++ b/layouts/_partials/assets/search-index.html @@ -13,13 +13,34 @@ Include it from every template that renders a search UI (search-input.html and ModalSearch.html do); without at least one inclusion per language the index asset is not published and the runtime fetch would 404. + + Hugo version gate: on Hugo < 0.164 a page that uses `resources.PostProcess` + silently prevents that page's `templates.Defer` blocks from executing — and + the theme's production stylesheet always uses `resources.PostProcess` (it is + how `css.PostCSS` is deferred so PurgeCSS reads a complete hugo_stats.json). + The deferred index would then never publish and its raw placeholder token + would leak into the rendered page. So on Hugo < 0.164 publish the index + EAGERLY instead: correct, at the cost of the serial-render stall that + templates.Defer was introduced to avoid. Guard the eager path to run once + per language via site.Store. Hugo >= 0.164 keeps the deferred path. + (hugo.Version.Compare returns > 0 when the running version is older.) */ -}} -{{- with (templates.Defer (dict - "key" (printf "flexsearch-index-%s" site.Language.Lang) - "data" (dict "site" site) -)) -}} - {{- $site := .site -}} - {{- $docs := partial "utilities/GetSearchDocs.html" (dict "site" $site) -}} - {{- $index := resources.FromString (partial "utilities/GetSearchIndexPath.html" $site) ($docs | jsonify) -}} - {{- $noop := $index.RelPermalink -}} +{{- if le (hugo.Version.Compare "0.164.0") 0 -}} + {{- with (templates.Defer (dict + "key" (printf "flexsearch-index-%s" site.Language.Lang) + "data" (dict "site" site) + )) -}} + {{- $site := .site -}} + {{- $docs := partial "utilities/GetSearchDocs.html" (dict "site" $site) -}} + {{- $index := resources.FromString (partial "utilities/GetSearchIndexPath.html" $site) ($docs | jsonify) -}} + {{- $noop := $index.RelPermalink -}} + {{- end -}} +{{- else -}} + {{- $guard := printf "flexsearch-index-eager-%s" site.Language.Lang -}} + {{- if not (site.Store.Get $guard) -}} + {{- site.Store.Set $guard true -}} + {{- $docs := partial "utilities/GetSearchDocs.html" (dict "site" site) -}} + {{- $index := resources.FromString (partial "utilities/GetSearchIndexPath.html" site) ($docs | jsonify) -}} + {{- $noop := $index.RelPermalink -}} + {{- end -}} {{- end -}}