From a8d130b1fd6f4b7940fe2fde414cbb346f3291c5 Mon Sep 17 00:00:00 2001 From: notleowang Date: Tue, 24 Nov 2026 14:49:53 -0700 Subject: [PATCH 1/3] Show a Search label on the search button The search button had no visible text, only Pagefind's icon and the keyboard shortcut, in grey on a fill and border that barely differ from the header. It now shows "Search", which Pagefind leaves out in compact mode. Pagefind's default label is its lowercase "search" keyboard hint, so the label is set explicitly. The label and icon use the GitHub button's text colour, #444 (9.24:1 on the button's #f8f9fa). Pagefind's #767676 is 4.31:1 there, below the 4.5:1 that text needs. Only the button is affected; the modal keeps Pagefind's colours. From 1025px to 1100px, just above the mobile menu, the nav doesn't fit the label and the shortcut, so the shortcut is hidden there, as on touch devices. The shortcut still works. In the mobile menu, the label is centred like the GitHub button's. Signed-off-by: notleowang --- sass/_valkey.scss | 13 +++++++++++-- static/assets/js/search.js | 4 +++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/sass/_valkey.scss b/sass/_valkey.scss index 4e4f2fc2..40de0755 100644 --- a/sass/_valkey.scss +++ b/sass/_valkey.scss @@ -267,14 +267,18 @@ p { display: flex; --pf-background: #f8f9fa; --pf-border: #dfe1e4; + // The label and icon. Pagefind's #767676 is too light for text on this background. + --pf-text-muted: #444; --pf-input-height: 100%; pagefind-modal-trigger { flex-grow: 1; } - // Pagefind hides its other keyboard hints on touch devices, but not this one - @media (hover: none) { + // Pagefind hides its other keyboard hints on touch devices, but not this one. Just above the + // mobile menu, the nav doesn't fit with the label and the shortcut, so the label stays. The + // shortcut still works there. + @media (hover: none), (min-width: 1025px) and (max-width: 1100px) { .pf-trigger-shortcut { display: none !important; } @@ -288,6 +292,11 @@ p { .pf-trigger-btn { justify-content: center !important; } + + // Centred like the GitHub button, instead of the label filling the button + .pf-trigger-text { + flex: none !important; + } } } } diff --git a/static/assets/js/search.js b/static/assets/js/search.js index 22950aa9..5f68e899 100644 --- a/static/assets/js/search.js +++ b/static/assets/js/search.js @@ -15,8 +15,10 @@ document.addEventListener('DOMContentLoaded', function() { addBreadcrumbsToResults(instance); putExactTitleMatchesFirst(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('compact', ''); + 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. From ca967b35561450cf8e7b2aa4aab458168cc06e01 Mon Sep 17 00:00:00 2001 From: notleowang Date: Tue, 24 Nov 2026 14:49:53 -0700 Subject: [PATCH 2/3] Put the search button before the GitHub button The search button now sits between the nav links and the GitHub button, so it's next to the other links rather than at the end of the header. In the mobile menu, it's above the GitHub button. The keyboard order follows the visual order. Signed-off-by: notleowang --- templates/default.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/default.html b/templates/default.html index fd7857ad..df51c67a 100644 --- a/templates/default.html +++ b/templates/default.html @@ -113,13 +113,13 @@ Participants Try Valkey + + {% include "includes/search-modal.html" %} GitHub Icon GitHub - - {% include "includes/search-modal.html" %} From dd3da60e2f4af1671076891a8b9d97910c51733e Mon Sep 17 00:00:00 2001 From: notleowang Date: Tue, 24 Nov 2026 16:53:48 -0700 Subject: [PATCH 3/3] Boost pages in search for keywords set in _data/search.toml Searching "migration" showed "Migration from Redis to Valkey" third, behind the atomic slot migration blog post and topic, which mention the word more. Each [[boost]] in _data/search.toml gives a page's URL and the keywords it should rank higher for. default.html adds the page's keywords as Pagefind metadata, and search.js gives that field a weight of 10 with Pagefind's metaWeights, twice its default title boost. The boost only applies to searches matching the keywords, and pages titled exactly what was searched still come first. The boosts are in a file rather than front matter because docs topics and commands come from other repositories; the file works for any page. A boost is keyed by URL, so it needs updating if its page moves. /topics/migration/ is boosted for "migration", and a ranking case checks that it's the first result. Signed-off-by: notleowang --- _data/search.toml | 14 ++++++++++++++ build/search-ranking.toml | 5 +++++ static/assets/js/search.js | 7 ++++++- templates/default.html | 10 +++++++++- 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 _data/search.toml diff --git a/_data/search.toml b/_data/search.toml new file mode 100644 index 00000000..2c3b5db5 --- /dev/null +++ b/_data/search.toml @@ -0,0 +1,14 @@ +# Tuning for the site search. +# +# Each [[boost]] ranks a page higher when a search matches one of its keywords, ahead of pages that +# only mention the words in their text. Pages titled exactly what was searched still come first. +# +# url: the page's path, as in its address, e.g. "/topics/migration/" +# keywords: words or phrases the page should rank higher for +# +# This works for any page, including docs topics and commands, whose content comes from other +# repositories. If a page moves, update its url here. + +[[boost]] +url = "/topics/migration/" +keywords = ["migration"] diff --git a/build/search-ranking.toml b/build/search-ranking.toml index 4a817836..e13ae851 100644 --- a/build/search-ranking.toml +++ b/build/search-ranking.toml @@ -119,3 +119,8 @@ top = 1 query = "migrate from redis" url = "/topics/migration/" top = 1 + +[[search]] +query = "migration" +url = "/topics/migration/" +top = 1 diff --git a/static/assets/js/search.js b/static/assets/js/search.js index 5f68e899..b23e27cd 100644 --- a/static/assets/js/search.js +++ b/static/assets/js/search.js @@ -9,7 +9,12 @@ document.addEventListener('DOMContentLoaded', function() { window.PagefindComponents.configureInstance('default', { // Favour exact word matches and longer pages over short pages with similar words. // Values based on git-scm.com's Pagefind setup. - ranking: { pageLength: 0.1, termFrequency: 0.1, termSaturation: 2, termSimilarity: 9 }, + ranking: { + pageLength: 0.1, termFrequency: 0.1, termSaturation: 2, termSimilarity: 9, + // Boost pages whose keywords in _data/search.toml match the search. Pagefind boosts + // title matches by 5 by default. + metaWeights: { keywords: 10 }, + }, }); const instance = window.PagefindComponents.getInstanceManager().getInstance('default'); addBreadcrumbsToResults(instance); diff --git a/templates/default.html b/templates/default.html index df51c67a..ab885d6c 100644 --- a/templates/default.html +++ b/templates/default.html @@ -39,7 +39,14 @@ {%- endif %} {%- endif %} {%- endif %} -{%- endif -%} +{%- endif %} +{#- Words that rank the page higher when a search matches them (metaWeights in search.js), from the + page's [[boost]] entries in _data/search.toml. #} +{%- set search_keywords = [] %} +{%- set search_tuning = load_data(path="_data/search.toml", format="toml", required=false) %} +{%- for boost in search_tuning?.boost | default(value=[]) %} + {%- if boost.url == current_path | default(value="") %}{% set_global search_keywords = [...search_keywords, ...boost.keywords] %}{% endif %} +{%- endfor -%} {% include "includes/head.html" %} @@ -129,6 +136,7 @@
{%- if breadcrumb %}{% endif %} + {%- if search_keywords %}{% endif %} {% block content %}{% endblock %}