Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions _data/search.toml
Original file line number Diff line number Diff line change
@@ -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"]
5 changes: 5 additions & 0 deletions build/search-ranking.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,8 @@ top = 1
query = "migrate from redis"
url = "/topics/migration/"
top = 1

[[search]]
query = "migration"
url = "/topics/migration/"
top = 1
13 changes: 11 additions & 2 deletions sass/_valkey.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions static/assets/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <body>, inside the nav it would be hidden while the mobile menu is closed.
Expand Down
14 changes: 11 additions & 3 deletions templates/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%}
<!DOCTYPE html>
<html lang="{{ page?.lang | default(value=config.default_language) }}">
{% include "includes/head.html" %}
Expand Down Expand Up @@ -113,13 +120,13 @@
</div>
<a role="menuitem" href="/participants/">Participants</a>
<a role="menuitem" href="/try-valkey/">Try Valkey</a>
<div id="site-search"></div>
{% include "includes/search-modal.html" %}
<a role="menuitem" href="https://github.com/valkey-io" target="_blank" class="github-button">
<img src="/img/IconGithub.svg" alt="GitHub Icon" width="16" height="16" />
GitHub
<!-- Star count will be injected here by JS -->
</a>
<div id="site-search"></div>
{% include "includes/search-modal.html" %}

</nav>
</div>
Expand All @@ -129,6 +136,7 @@
<div class="body" data-pagefind-meta="title:{{ search_title }}">
<span hidden data-pagefind-filter="exact_title:{{ search_title | lower }}"></span>
{%- if breadcrumb %}<span hidden data-pagefind-filter="breadcrumb:{{ breadcrumb }}"></span>{% endif %}
{%- if search_keywords %}<span hidden data-pagefind-meta="keywords:{{ search_keywords | join(sep=", ") }}"></span>{% endif %}
{% block content %}{% endblock %}
</div>
<div class="footer">
Expand Down