From b2ab4200f783b891e713c650a1c07ecaa656c5d5 Mon Sep 17 00:00:00 2001
From: Saurav Kumar Sinha <94630933+sauravsinhadev@users.noreply.github.com>
Date: Thu, 3 Dec 2026 16:52:35 +0000
Subject: [PATCH] Improve search UI and UX
---
CHANGELOG.md | 37 ++++
assets/js/search.js | 361 +++++++++++++++++++++++++++++++++--
assets/theme-css/search.css | 78 ++++++++
layouts/partials/navbar.html | 13 +-
pyproject.toml | 2 +-
5 files changed, 472 insertions(+), 19 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8c692128..d289ad7f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,40 @@
+# scientific-python-hugo-theme 0.24rc0
+
+We're happy to announce the release of scientific-python-hugo-theme 0.24rc0!
+
+## Bug Fixes
+
+- Update hugo-atom-layout to restore `utm_source` links ([#719](https://github.com/scientific-python/scientific-python-hugo-theme/pull/719)).
+- Update hugo-atom-layout to limit the home feed to main sections ([#720](https://github.com/scientific-python/scientific-python-hugo-theme/pull/720)).
+- Only add discourse link when configured ([#722](https://github.com/scientific-python/scientific-python-hugo-theme/pull/722)).
+
+## Documentation
+
+- Document cloning submodules recursively ([#717](https://github.com/scientific-python/scientific-python-hugo-theme/pull/717)).
+
+## Maintenance
+
+- Remove learn.scientific-python.org from Netlify preview build ([#727](https://github.com/scientific-python/scientific-python-hugo-theme/pull/727)).
+- Upgrade Mermaid to 12.2.0 ([#731](https://github.com/scientific-python/scientific-python-hugo-theme/pull/731)).
+
+## Contributors
+
+4 authors added to this release (alphabetically):
+
+- Agriya Khetarpal ([@agriyakhetarpal](https://github.com/agriyakhetarpal))
+- Inessa Pawson ([@InessaPawson](https://github.com/InessaPawson))
+- Jarrod Millman ([@jarrodmillman](https://github.com/jarrodmillman))
+- Stefan van der Walt ([@stefanv](https://github.com/stefanv))
+
+3 reviewers added to this release (alphabetically):
+
+- Agriya Khetarpal ([@agriyakhetarpal](https://github.com/agriyakhetarpal))
+- Jarrod Millman ([@jarrodmillman](https://github.com/jarrodmillman))
+- Stefan van der Walt ([@stefanv](https://github.com/stefanv))
+
+_These lists are automatically generated, and may not be complete or may contain
+duplicates._
+
# scientific-python-hugo-theme 0.23
We're happy to announce the release of scientific-python-hugo-theme 0.23!
diff --git a/assets/js/search.js b/assets/js/search.js
index 459df837..bbe0ce3c 100644
--- a/assets/js/search.js
+++ b/assets/js/search.js
@@ -1,8 +1,10 @@
"use strict";
window.addEventListener("DOMContentLoaded", () => {
- let searchDialog = document.querySelector(".search-dialog");
- let searchButton = document.getElementById("search-button");
+ const searchDialog = document.querySelector(".search-dialog");
+ const searchButton =
+ document.getElementById("search-button") ||
+ document.querySelector(".search-button");
// Do nothing here if search is not enabled.
if (!searchDialog || !searchButton) return;
@@ -17,8 +19,338 @@ window.addEventListener("DOMContentLoaded", () => {
showSubResults: true,
});
- let showSearch = () => searchDialog.showModal();
- let hideSearch = () => searchDialog.close();
+ // Cache links once at load for zero-query quick jumps
+ const cachedLinks = Array.from(document.querySelectorAll("a[href]"))
+ .map((a) => ({
+ label: (a.innerText || a.textContent || "").trim(),
+ href: a.getAttribute("href"),
+ }))
+ .filter(
+ (item) =>
+ item.label &&
+ item.label.length > 1 &&
+ item.label.length < 36 &&
+ item.href &&
+ !item.href.startsWith("#") &&
+ !item.href.startsWith("javascript:")
+ )
+ .slice(0, 8);
+
+ let uiInitialized = false;
+ let renderQuickJumps = () => {};
+
+ const applyCleanLightPalette = () => {
+ if (!document.getElementById("sp-clean-search-style")) {
+ const style = document.createElement("style");
+ style.id = "sp-clean-search-style";
+ style.textContent = `
+ dialog.search-dialog {
+ background: #ffffff !important;
+ color: #1f2328 !important;
+ border: 1px solid #d0d7de !important;
+ border-radius: 12px !important;
+ box-shadow: 0 12px 28px rgba(27, 31, 36, 0.12) !important;
+ padding: 0 !important;
+ margin: auto !important;
+ outline: none !important;
+ max-width: min(720px, calc(100vw - 32px)) !important;
+ max-height: calc(100vh - 48px) !important;
+ width: 100% !important;
+ display: flex !important;
+ flex-direction: column !important;
+ overflow: hidden !important;
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif !important;
+ }
+
+ dialog.search-dialog:not([open]) {
+ display: none !important;
+ }
+
+ dialog.search-dialog::backdrop {
+ background: rgba(27, 31, 36, 0.22) !important;
+ }
+
+ dialog.search-dialog .pagefind-ui,
+ dialog.search-dialog .pagefind-ui__form {
+ background: #ffffff !important;
+ color: #1f2328 !important;
+ border: none !important;
+ box-shadow: none !important;
+ outline: none !important;
+ display: flex !important;
+ flex-direction: column !important;
+ min-height: 0 !important;
+ flex: 1 1 auto !important;
+ }
+
+ dialog.search-dialog .pagefind-ui__form {
+ position: relative !important;
+ flex: 0 0 auto !important;
+ }
+
+ dialog.search-dialog input[type="search"],
+ dialog.search-dialog .pagefind-ui__search-input {
+ width: 100% !important;
+ height: 52px !important;
+ box-sizing: border-box !important;
+ background: #ffffff !important;
+ color: #1f2328 !important;
+ border: none !important;
+ border-bottom: 1px solid #d8dee4 !important;
+ border-radius: 0 !important;
+ padding: 0 96px 0 42px !important;
+ font-size: 15px !important;
+ font-weight: 400 !important;
+ line-height: 52px !important;
+ outline: none !important;
+ box-shadow: none !important;
+ caret-color: #1f2328 !important;
+ }
+
+ dialog.search-dialog input[type="search"]::placeholder,
+ dialog.search-dialog .pagefind-ui__search-input::placeholder {
+ color: #656d76 !important;
+ font-family: inherit !important;
+ font-size: 14px !important;
+ opacity: 1 !important;
+ }
+
+ /* Compact height (24px) & vertically centered inside the 52px input */
+ dialog.search-dialog button[aria-label*="Clear" i],
+ dialog.search-dialog .pagefind-ui__search-clear,
+ .sp-clear-pill {
+ position: absolute !important;
+ right: 14px !important;
+ top: 26px !important;
+ transform: translateY(-50%) !important;
+ height: 24px !important;
+ box-sizing: border-box !important;
+ display: inline-flex !important;
+ align-items: center !important;
+ justify-content: center !important;
+ gap: 5px !important;
+ background: #ffffff !important;
+ color: #57606a !important;
+ border: 1px solid #d0d7de !important;
+ border-radius: 6px !important;
+ padding: 0 7px !important;
+ font-size: 11px !important;
+ font-weight: 500 !important;
+ line-height: 1 !important;
+ cursor: pointer !important;
+ box-shadow: none !important;
+ outline: none !important;
+ z-index: 3 !important;
+ }
+
+ dialog.search-dialog button[aria-label*="Clear" i]:hover,
+ dialog.search-dialog .pagefind-ui__search-clear:hover,
+ .sp-clear-pill:hover {
+ background: #f6f8fa !important;
+ color: #1f2328 !important;
+ border-color: #afb8c1 !important;
+ }
+
+ .sp-esc-tag {
+ display: inline-flex;
+ align-items: center;
+ height: 16px;
+ padding: 0 4px;
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
+ font-size: 10px;
+ line-height: 1;
+ color: #57606a;
+ background: #f6f8fa;
+ border: 1px solid #d8dee4;
+ border-radius: 3px;
+ }
+
+ .sp-quick-jumps {
+ padding: 10px 14px 14px 14px;
+ background: #ffffff;
+ overflow-y: auto;
+ overscroll-behavior: contain;
+ }
+
+ .sp-quick-heading {
+ padding: 6px 4px 8px 4px;
+ font-size: 12px;
+ font-weight: 600;
+ color: #57606a;
+ line-height: 16px;
+ }
+
+ .sp-quick-row {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ padding: 9px 10px;
+ margin-bottom: 4px;
+ border-radius: 8px;
+ font-size: 14px;
+ line-height: 20px;
+ color: #1f2328;
+ text-decoration: none;
+ background: #ffffff;
+ }
+
+ .sp-quick-row:hover {
+ background: #f6f8fa;
+ }
+
+ .sp-quick-row svg {
+ width: 16px;
+ height: 16px;
+ flex-shrink: 0;
+ color: #57606a;
+ stroke: currentColor;
+ fill: none;
+ stroke-width: 1.6;
+ }
+
+ /* Scrollable results container with clean outer & inner spacing */
+ dialog.search-dialog .pagefind-ui__drawer {
+ background: #ffffff !important;
+ border: none !important;
+ box-shadow: none !important;
+ overflow: hidden !important;
+ display: flex !important;
+ flex-direction: column !important;
+ min-height: 0 !important;
+ flex: 1 1 auto !important;
+ }
+
+ dialog.search-dialog .pagefind-ui__results-area {
+ margin: 12px 14px 16px 14px !important;
+ padding: 0 4px 0 0 !important;
+ background: #ffffff !important;
+ border: none !important;
+ box-shadow: none !important;
+ max-height: min(60vh, 480px) !important;
+ overflow-y: auto !important;
+ overscroll-behavior: contain !important;
+ -webkit-overflow-scrolling: touch !important;
+ }
+
+ dialog.search-dialog .pagefind-ui__message {
+ margin: 0 4px 12px 4px !important;
+ color: #57606a !important;
+ font-size: 13px !important;
+ }
+
+ dialog.search-dialog .pagefind-ui__result {
+ background: #ffffff !important;
+ border: 1px solid #e6ebf1 !important;
+ border-radius: 10px !important;
+ box-shadow: none !important;
+ padding: 14px 16px !important;
+ margin: 0 0 10px 0 !important;
+ }
+
+ dialog.search-dialog .pagefind-ui__result:hover {
+ background: #f6f8fa !important;
+ border-color: #d0d7de !important;
+ }
+
+ dialog.search-dialog mark {
+ background: #fff8c5 !important;
+ color: #1f2328 !important;
+ border-radius: 2px !important;
+ padding: 0 2px !important;
+ }
+ `;
+ document.head.appendChild(style);
+ }
+
+ if (uiInitialized) return;
+
+ const input = searchDialog.querySelector(
+ 'input[type="search"], .pagefind-ui__search-input'
+ );
+ const formEl =
+ input?.closest("form, .pagefind-ui__form") || input?.parentElement;
+ if (!input || !formEl) return;
+
+ uiInitialized = true;
+ input.placeholder = "Search docs...";
+
+ const handleClearOrClose = (evt) => {
+ evt.stopPropagation();
+ if (input.value && input.value.trim().length > 0) {
+ evt.preventDefault();
+ input.value = "";
+ input.dispatchEvent(new Event("input", { bubbles: true }));
+ input.focus();
+ } else {
+ evt.preventDefault();
+ searchDialog.close();
+ }
+ };
+
+ const existingClear = formEl.querySelector(
+ 'button[aria-label*="Clear" i], .pagefind-ui__search-clear'
+ );
+ if (existingClear) {
+ existingClear.classList.add("sp-clear-pill");
+ existingClear.innerHTML = `ClearEsc`;
+ existingClear.addEventListener("click", handleClearOrClose);
+ } else {
+ const clearBtn = document.createElement("button");
+ clearBtn.type = "button";
+ clearBtn.className = "sp-clear-pill";
+ clearBtn.innerHTML = `ClearEsc`;
+ clearBtn.addEventListener("click", handleClearOrClose);
+ formEl.appendChild(clearBtn);
+ }
+
+ const quickBox = document.createElement("div");
+ quickBox.className = "sp-quick-jumps";
+ formEl.insertAdjacentElement("afterend", quickBox);
+
+ const docIcon = `