From f929b8f1ed6209d534b12358b3ce48d641278dd8 Mon Sep 17 00:00:00 2001 From: David Karlsson <35727626+dvdksn@users.noreply.github.com> Date: Thu, 5 Feb 2026 17:56:59 +0000 Subject: [PATCH] site: implement pagefind component ui for search modal - Add pagefind-component-ui.css and .js assets - Replace search bar with custom button that opens modal - Add custom result template with Tailwind classes - Add dark mode styling for modal and result highlights - Support Cmd/Ctrl+K keyboard shortcut Assisted-By: cagent --- .htmltest.yml | 1 + assets/css/pagefind.css | 25 +++ assets/css/style.css | 1 + layouts/partials/head.html | 1 + layouts/partials/search-bar.html | 287 +++++++++++-------------------- 5 files changed, 124 insertions(+), 191 deletions(-) create mode 100644 assets/css/pagefind.css diff --git a/.htmltest.yml b/.htmltest.yml index 1be65b8235..ea2330397f 100644 --- a/.htmltest.yml +++ b/.htmltest.yml @@ -10,6 +10,7 @@ IgnoreURLs: - "^/reference/api/hub/.*$" - "^/reference/api/engine/v.+/#.*$" - "^/reference/api/registry/.*$" +- "^/pagefind/.*$" IgnoreDirs: - "registry/configuration" - "compose/compose-file" # temporarily ignore until upstream is fixed diff --git a/assets/css/pagefind.css b/assets/css/pagefind.css new file mode 100644 index 0000000000..a6619c3b10 --- /dev/null +++ b/assets/css/pagefind.css @@ -0,0 +1,25 @@ +/* Pagefind Component UI Customizations */ + +/* Dark mode variables for modal */ +.dark pagefind-modal { + --pf-text: var(--color-gray-100); + --pf-text-secondary: var(--color-gray-300); + --pf-text-muted: var(--color-gray-400); + --pf-background: var(--color-gray-900); + --pf-border: var(--color-gray-700); + --pf-border-focus: var(--color-blue-400); + --pf-hover: var(--color-gray-800); +} + +/* Highlight marks in results */ +pagefind-results mark { + background-color: var(--color-yellow-200); + color: inherit; + padding: 0 0.125rem; + border-radius: 0.125rem; +} + +.dark pagefind-results mark { + background-color: rgba(255, 204, 72, 0.3); + color: white; +} diff --git a/assets/css/style.css b/assets/css/style.css index 8315621f42..f63fc6f5ae 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -38,6 +38,7 @@ @import "global.css"; } @import "utilities.css"; +@import "pagefind.css"; @import "syntax-dark.css"; @import "syntax-light.css"; @import "components.css"; diff --git a/layouts/partials/head.html b/layouts/partials/head.html index dfc8f368d6..ea19cfcd95 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -5,6 +5,7 @@ {{ end -}} {{ partial "utils/css.html" "-" }} + {{- if hugo.IsProduction -}} - + // Show/hide placeholder based on search state + const instance = getInstanceManager().getInstance('default'); + instance.on('search', (term) => { + placeholder.hidden = !!term; + }); + instance.on('results', () => { + placeholder.hidden = !!instance.searchTerm; + }); + + // Open modal + const openModal = () => modal.open?.(); + document.getElementById('search-modal-trigger').addEventListener('click', openModal); + document.addEventListener('keydown', (e) => { + if ((e.metaKey || e.ctrlKey) && e.key === 'k') { + e.preventDefault(); + openModal(); + } + }); +