From 0d24df31addf4484629ea9c402ad4d70ceeed62d Mon Sep 17 00:00:00 2001 From: noether Date: Sun, 11 Oct 2026 08:59:18 -0600 Subject: [PATCH] search: replace Fuse.js with Pagefind (Default UI) + full UI polish Remove the legacy Fuse.js search from html-head.html (it double-loaded with the new Pagefind UI; backup kept at html-head.html.bkup) and add a Pagefind Default-UI partial (search.html) injected into the sidebar via menu.html. Index scoping: tag the article element with data-pagefind-body in baseof.html, term.html, and posts/{single,list}.html so Pagefind indexes page content only (pages without the tag are skipped; 404.html stays untagged). search.html (all overrides #search-scoped, since pagefind-ui.css loads in after the head CSS): - compact input/magnifier/clear-button fitted to the sidebar; clear button uses fixed px (not %) because the results drawer is an in-flow child of the form, which stretches the form to results height - hide the empty .result-thumb placeholder (no images in the index) that was pushing result text ~90px right - restyle matched-term from UA yellow to subdued slate - keyboard navigation (Pagefind 1.5.2 has none; stock Enter is a silent no-op): capture-phase keydown implements ArrowUp/Down highlighting with wraparound across top-level hits AND their nested sub-results (each sub highlights its own .result-nested row), Enter opens the highlighted result (or the top result), and a fingerprint-aware MutationObserver keeps the highlight across Pagefind's async re-renders without resetting it on every DOM patch --- .../layouts/_partials/docs/html-head.html | 9 +- .../_partials/docs/html-head.html.bkup | 60 ++++++ .../layouts/_partials/docs/search.html | 176 +++++++++++++++++- themes/hugo-book/layouts/baseof.html | 2 +- themes/hugo-book/layouts/posts/list.html | 2 +- themes/hugo-book/layouts/posts/single.html | 2 +- themes/hugo-book/layouts/term.html | 2 +- 7 files changed, 241 insertions(+), 12 deletions(-) create mode 100644 themes/hugo-book/layouts/_partials/docs/html-head.html.bkup diff --git a/themes/hugo-book/layouts/_partials/docs/html-head.html b/themes/hugo-book/layouts/_partials/docs/html-head.html index 0747c40..208dd11 100644 --- a/themes/hugo-book/layouts/_partials/docs/html-head.html +++ b/themes/hugo-book/layouts/_partials/docs/html-head.html @@ -32,13 +32,8 @@ https://github.com/alex-shpak/hugo-book {{- $styles := resources.Get "book.scss" | resources.ExecuteAsTemplate "book.scss" . | css.Sass | resources.Minify | resources.Fingerprint }} - -{{- if default true .Site.Params.BookSearch -}} - {{- $searchJSFile := printf "%s.search.js" .Language.Lang }} - {{- $searchJS := resources.Get "search.js" | resources.ExecuteAsTemplate $searchJSFile . | resources.Minify | resources.Fingerprint }} - - -{{ end -}} + {{- if .Site.Params.BookServiceWorker -}} diff --git a/themes/hugo-book/layouts/_partials/docs/html-head.html.bkup b/themes/hugo-book/layouts/_partials/docs/html-head.html.bkup new file mode 100644 index 0000000..0747c40 --- /dev/null +++ b/themes/hugo-book/layouts/_partials/docs/html-head.html.bkup @@ -0,0 +1,60 @@ +{{ "" | safeHTML }} + + + + + + + + +{{- with .Page.Params.BookHref -}} + +{{- end -}} + +{{ partial "opengraph.html" . }} +{{ partial "schema.html" . }} + +{{ partial "docs/html-head-title" . }} +{{ partial "docs/html-head-favicon" . }} + +{{- $manifest := resources.Get "manifest.json" | resources.ExecuteAsTemplate "manifest.json" . }} + + + +{{- range .Translations }} + +{{- end -}} + + +{{- $styles := resources.Get "book.scss" | resources.ExecuteAsTemplate "book.scss" . | css.Sass | resources.Minify | resources.Fingerprint }} + + + +{{- if default true .Site.Params.BookSearch -}} + {{- $searchJSFile := printf "%s.search.js" .Language.Lang }} + {{- $searchJS := resources.Get "search.js" | resources.ExecuteAsTemplate $searchJSFile . | resources.Minify | resources.Fingerprint }} + + +{{ end -}} + + +{{- if .Site.Params.BookServiceWorker -}} + {{- $swJS := resources.Get "sw-register.js" | resources.ExecuteAsTemplate "sw.js" . | resources.Minify | resources.Fingerprint }} + +{{ end -}} + +{{ partial "google_analytics.html" . }} + + +{{- with .OutputFormats.Get "rss" -}} + {{ printf `` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }} +{{ end -}} + +{{- define "integrity" -}} + {{- if (urls.Parse .Permalink).Host -}} + integrity="{{ .Data.Integrity }}" crossorigin="anonymous" + {{- end -}} +{{- end -}} diff --git a/themes/hugo-book/layouts/_partials/docs/search.html b/themes/hugo-book/layouts/_partials/docs/search.html index 97bc8a1..df9a832 100644 --- a/themes/hugo-book/layouts/_partials/docs/search.html +++ b/themes/hugo-book/layouts/_partials/docs/search.html @@ -1,10 +1,184 @@ {{ if default true .Site.Params.BookSearch }} + {{ end }} diff --git a/themes/hugo-book/layouts/baseof.html b/themes/hugo-book/layouts/baseof.html index c1b0d97..f95f9cf 100644 --- a/themes/hugo-book/layouts/baseof.html +++ b/themes/hugo-book/layouts/baseof.html @@ -87,7 +87,7 @@ {{ end }} {{ define "main" }} -
+
{{- .Content -}}
{{ end }} diff --git a/themes/hugo-book/layouts/posts/list.html b/themes/hugo-book/layouts/posts/list.html index 9efd272..2d48a77 100644 --- a/themes/hugo-book/layouts/posts/list.html +++ b/themes/hugo-book/layouts/posts/list.html @@ -1,6 +1,6 @@ {{ define "main" }} {{ range sort .Paginator.Pages }} -
+

{{ partial "docs/title" . }}

diff --git a/themes/hugo-book/layouts/posts/single.html b/themes/hugo-book/layouts/posts/single.html index 232e14e..69e1737 100644 --- a/themes/hugo-book/layouts/posts/single.html +++ b/themes/hugo-book/layouts/posts/single.html @@ -1,5 +1,5 @@ {{ define "main" }} -
+

{{ partial "docs/title" . }}

diff --git a/themes/hugo-book/layouts/term.html b/themes/hugo-book/layouts/term.html index 674692e..e01468b 100644 --- a/themes/hugo-book/layouts/term.html +++ b/themes/hugo-book/layouts/term.html @@ -1,6 +1,6 @@ {{ define "main" }} {{ range sort .Paginator.Pages }} -