text}, skipping redirect stubs, the 404 page and HTML
- fragments that aren't full pages."""
+ """Return {URL: text}, skipping redirect stubs, the 404 page, pages
+ marked data-search-unindexed (such as the search page) and HTML fragments that
+ aren't full pages."""
pages = {}
for path in public.rglob("*.html"):
source = path.read_text(encoding="utf-8", errors="replace")
is_redirect = '(.*?)", source, re.DOTALL)
diff --git a/content/search.md b/content/search.md
new file mode 100644
index 00000000..d573f60e
--- /dev/null
+++ b/content/search.md
@@ -0,0 +1,4 @@
++++
+title = "Search"
+template = "search.html"
++++
diff --git a/sass/_valkey.scss b/sass/_valkey.scss
index e050d92d..192fc233 100644
--- a/sass/_valkey.scss
+++ b/sass/_valkey.scss
@@ -2990,8 +2990,8 @@ blockquote {
.calendar-nav .calendar-nav-title { font-size: 1.8rem; min-width: auto; }
}
-// Where a search result sits in the site
-pagefind-modal .search-result-breadcrumb {
+// Where a search result sits in the site, in the search modal and on the search page
+pagefind-results .search-result-breadcrumb {
margin: 0 0 4px;
color: var(--pf-text-secondary);
font-size: 13px;
diff --git a/static/assets/js/search.js b/static/assets/js/search.js
index 3c00b446..c52b1622 100644
--- a/static/assets/js/search.js
+++ b/static/assets/js/search.js
@@ -4,9 +4,28 @@ document.addEventListener('DOMContentLoaded', function() {
// Without a search index, such as under zola serve, there is no search button.
if (!window.PagefindComponents || !slot || !modalContents) return;
- // Configure before creating the elements: the first element to connect creates the
- // instance with default settings, and configuration after that is ignored.
- window.PagefindComponents.configureInstance('default', {
+ setUpInstance('default');
+
+ // Not compact, so the button has a visible "Search" label, not only an icon. Pagefind's default
+ // label is its lowercase "search" keyboard hint.
+ const trigger = document.createElement('pagefind-modal-trigger');
+ trigger.setAttribute('placeholder', 'Search');
+ keepScrollPositionOnClose(trigger);
+ slot.append(trigger);
+ // The modal goes on , inside the nav it would be hidden while the mobile menu is closed.
+ // The it's built from is never shown, so it can be anywhere.
+ document.body.append(createModal(modalContents));
+
+ const page = document.getElementById('search-page');
+ const pageContents = document.getElementById('search-page-contents');
+ if (page && pageContents) createSearchPage(page, pageContents);
+});
+
+// Sets up a Pagefind instance for the site: the modal uses 'default' and the search page 'page'.
+// Configure before creating the instance's elements: the first element to connect creates the
+// instance with default settings, and configuration after that is ignored.
+function setUpInstance(name) {
+ window.PagefindComponents.configureInstance(name, {
// Favour exact word matches and longer pages over short pages with similar words.
// Values based on git-scm.com's Pagefind setup.
ranking: {
@@ -16,20 +35,30 @@ document.addEventListener('DOMContentLoaded', function() {
metaWeights: { keywords: 10 },
},
});
- const instance = window.PagefindComponents.getInstanceManager().getInstance('default');
+ const instance = window.PagefindComponents.getInstanceManager().getInstance(name);
addBreadcrumbsToResults(instance);
putExactTitleMatchesFirst(instance);
+ return instance;
+}
- // Not compact, so the button has a visible "Search" label, not only an icon. Pagefind's default
- // label is its lowercase "search" keyboard hint.
- const trigger = document.createElement('pagefind-modal-trigger');
- trigger.setAttribute('placeholder', 'Search');
- keepScrollPositionOnClose(trigger);
- slot.append(trigger);
- // The modal goes on , inside the nav it would be hidden while the mobile menu is closed.
- // The it's built from is never shown, so it can be anywhere.
- document.body.append(createModal(modalContents));
-});
+// The search page, templates/search.html. /search/?q= searches for , and q follows
+// what's typed, so the address can be shared. Pagefind's search event comes after
+// stops for its debounce, so the address changes once typing pauses, not on every key.
+// replaceState keeps Back going to the previous page, rather than through each search.
+function createSearchPage(container, contents) {
+ const instance = setUpInstance('page');
+ container.append(contents.content.cloneNode(true));
+
+ instance.on('search', function(term) {
+ const url = new URL(window.location.href);
+ if (term) url.searchParams.set('q', term);
+ else url.searchParams.delete('q');
+ if (url.href !== window.location.href) window.history.replaceState(window.history.state, '', url);
+ });
+
+ const query = new URLSearchParams(window.location.search).get('q');
+ if (query) instance.triggerSearch(query);
+}
// Each page's breadcrumb is a filter rather than metadata, since Pagefind searches metadata and
// breadcrumbs shouldn't change the results. The result template only sees metadata, so this copies
diff --git a/templates/includes/search-modal.html b/templates/includes/search-modal.html
index 15327739..7babf066 100644
--- a/templates/includes/search-modal.html
+++ b/templates/includes/search-modal.html
@@ -2,42 +2,14 @@
They're in a so the Pagefind elements stay inactive until the modal has moved them
into its dialog; otherwise each one initializes twice. This is Pagefind's default modal, written
- out so the results can use the result template below. It must stay outside .body, the part of
- the page Pagefind indexes (root_selector in pagefind.yml).
-
- The result template is Pagefind's built-in one (https://pagefind.app/docs/components/results/),
- plus each result's breadcrumb, so the user can see where the page is in the site. It uses
- Pagefind's {{ }} syntax, so it's in a raw block to keep Zola from rendering it. #}
+ out so the results can use the site's result template. It must stay outside .body, the part of
+ the page Pagefind indexes (root_selector in pagefind.yml). #}
-
+ {% include "includes/search-result.html" %}
diff --git a/templates/includes/search-result.html b/templates/includes/search-result.html
new file mode 100644
index 00000000..38f97e64
--- /dev/null
+++ b/templates/includes/search-result.html
@@ -0,0 +1,31 @@
+{#- The template for each search result, shared by the search modal and the search page. Goes inside
+ a .
+
+ It's Pagefind's built-in result template (https://pagefind.app/docs/components/results/), plus
+ each result's breadcrumb, so the user can see where the page is in the site. It uses Pagefind's
+ {{ }} syntax, so it's in a raw block to keep Zola from rendering it. #}
+
diff --git a/templates/search.html b/templates/search.html
new file mode 100644
index 00000000..df5547db
--- /dev/null
+++ b/templates/search.html
@@ -0,0 +1,27 @@
+{% extends "default.html" %}
+
+{#- The search page. /search/?q= shows the results for , so a search can be linked to.
+ static/assets/js/search.js copies the contents below into #search-page and keeps q in the
+ address up to date. They're in a so search.js can configure their Pagefind instance
+ before they start, as for the modal.
+
+ The page isn't indexed itself: data-search-unindexed tells build/check-search-index.py not to
+ expect it. #}
+{% block content %}
+