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/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..b23e27cd 100644 --- a/static/assets/js/search.js +++ b/static/assets/js/search.js @@ -9,14 +9,21 @@ 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); 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. diff --git a/templates/default.html b/templates/default.html index fd7857ad..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" %} @@ -113,13 +120,13 @@ Participants Try Valkey + + {% include "includes/search-modal.html" %}