From 800c102b34054209ac52347da70b811266b51705 Mon Sep 17 00:00:00 2001 From: Daniel Frankcom Date: Thu, 29 Oct 2026 09:32:10 -0700 Subject: [PATCH 1/6] Federate docs search with other Valkey sites Signed-off-by: Daniel Frankcom --- .github/workflows/deploy-site.yml | 9 +- .github/workflows/docs-site.yml | 33 +++++++ docs-site/astro.config.mjs | 1 + docs-site/scripts/index-copies.sh | 128 ++++++++++++++++++++++++++ docs-site/src/components/Search.astro | 103 +++++++++++++++++++++ docs-site/src/cross-site-search.json | 5 + 6 files changed, 276 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/docs-site.yml create mode 100755 docs-site/scripts/index-copies.sh create mode 100644 docs-site/src/components/Search.astro create mode 100644 docs-site/src/cross-site-search.json diff --git a/.github/workflows/deploy-site.yml b/.github/workflows/deploy-site.yml index 5f36e3fc..67906648 100644 --- a/.github/workflows/deploy-site.yml +++ b/.github/workflows/deploy-site.yml @@ -7,11 +7,9 @@ on: - 'docs-site/**' workflow_dispatch: -# Allow this job to clone the repo and create a page deployment +# Only the deploy job can publish. permissions: contents: read - pages: write - id-token: write jobs: build: @@ -23,10 +21,15 @@ jobs: uses: withastro/action@e84f40bd8d2caa9e768ec82ad30dd81f0b280853 # v6 with: path: ./docs-site # The root location of your Astro project inside the repository. + # Also add copies of the search index for other Valkey sites to consume. + build-cmd: npm run build && ./scripts/index-copies.sh build deploy: needs: build runs-on: ubuntu-latest + permissions: + pages: write + id-token: write environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} diff --git a/.github/workflows/docs-site.yml b/.github/workflows/docs-site.yml new file mode 100644 index 00000000..41154314 --- /dev/null +++ b/.github/workflows/docs-site.yml @@ -0,0 +1,33 @@ +name: Docs site + +on: + pull_request: + branches: [ main ] + paths: + - 'docs-site/**' + - '.github/workflows/docs-site.yml' + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + defaults: + run: + working-directory: docs-site + steps: + - name: Checkout code + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + - name: Set up Node.js + uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6 + with: + node-version: '24' + cache: npm + cache-dependency-path: docs-site/package-lock.json + - name: Install dependencies + run: npm ci + - name: Build the docs site + run: npm run build + - name: Check the Pagefind index version served by other sites is compatible with this site + run: ./scripts/index-copies.sh check diff --git a/docs-site/astro.config.mjs b/docs-site/astro.config.mjs index e9707c65..537af48d 100644 --- a/docs-site/astro.config.mjs +++ b/docs-site/astro.config.mjs @@ -8,6 +8,7 @@ export default defineConfig({ integrations: [ starlight({ title: 'Valkey Admin', + components: { Search: './src/components/Search.astro' }, head: [ { tag: 'script', diff --git a/docs-site/scripts/index-copies.sh b/docs-site/scripts/index-copies.sh new file mode 100755 index 00000000..aeac70a8 --- /dev/null +++ b/docs-site/scripts/index-copies.sh @@ -0,0 +1,128 @@ +#!/usr/bin/env bash +# Builds copies of this site's search index at /pagefind/v/, one for every Pagefind minor version from the +# oldest a Valkey site runs up to the newest release. Pagefind only merges indexes built with its own minor version, so +# this site must provide any version other sites may need. +# +# scripts/index-copies.sh build produces the necessary indexes for other sites to consume +# scripts/index-copies.sh check checks current Pagefind is compatible with indexes hosted by other sites +# +# Both fail if a site that has set up cross-site search has no copy for this build's Pagefind minor version yet. +# Redeploying that site usually adds the copy. + +set -euo pipefail +case ${1:-} in build | check) ;; *) echo "usage: $0 build|check" >&2; exit 2 ;; esac + +cd "$(dirname "$0")/.." +OTHER_SITES=$(jq -r '.otherSites[]' src/cross-site-search.json) +TMP=$(mktemp -d) +trap 'rm -rf "$TMP"' EXIT + +minor_version() { cut -d. -f1-2 <<< "$1"; } # 1.5.2 -> 1.5 + +# Prints the Pagefind version of the index at $1, "none" if it has no usable index (a 404, or an entry file without a +# release number), or "down" for anything else, such as a 503 or no answer. +index_state() { + local status version + rm -f "$TMP/entry.json" # clean any prior state + status=$(curl -sS --retry 3 --retry-connrefused --max-time 20 -o "$TMP/entry.json" -w '%{http_code}' \ + "${1}pagefind-entry.json" 2>/dev/null) || status=failed + case $status in + 404) echo none; return ;; + 200) ;; + *) echo down; return ;; + esac + version=$(jq -r .version "$TMP/entry.json" 2>/dev/null) || version= + if [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "$version" + else + echo none + fi +} + +check_other_sites() { + local this_minor index version missing=() + this_minor=$(minor_version "$1") + for index in $OTHER_SITES; do + # Check whether the site has any Pagefind index at all. + version=$(index_state "$index") + case $version in + none) continue ;; + down) missing+=("$index"); continue ;; + esac + # Check whether the site publishes its own version-specific index version. + case $(index_state "${index}v$(minor_version "$version")/") in + none) continue ;; # hasn't set up cross-site search + down) missing+=("$index"); continue ;; + esac + # Check whether the needed version is available. + case $(index_state "${index}v${this_minor}/") in + none | down) missing+=("$index") ;; + esac + done + [ "${#missing[@]}" -gt 0 ] || return 0 + + cat >&2 << EOF +::error::These sites have no copy of their search index for Pagefind ${this_minor} yet, or can't be reached: ${missing[*]} +Deployed now, this site's search would leave them out. Either: + - redeploy them first, which adds a ${this_minor} copy if ${this_minor} is within the versions they publish. + - keep this site on the Pagefind version it uses now. +EOF + return 1 +} + +# Index versions to publish from this site. Finds the oldest version a Valkey site uses, and gathers each minor version +# of Pagefind published since up to the newest release. +versions_to_copy() { + local in_use=("$1") index state oldest + for index in $OTHER_SITES; do + state=$(index_state "$index") + case $state in + none) echo "::warning::${index} has no index; its version isn't counted" >&2 ;; + # Without its version, this deploy could stop publishing the copy that site's search uses. + down) echo "::error::${index} can't be reached; re-run this deploy once it can" >&2; return 1 ;; + *) echo "${index} runs Pagefind ${state}" >&2; in_use+=("$state") ;; + esac + done + oldest=$(printf '%s\n' "${in_use[@]}" | sort -V | head -1) + curl -fsS --retry 3 --retry-connrefused --max-time 20 https://registry.npmjs.org/pagefind | jq -r --arg oldest "$(minor_version "$oldest")" ' + def minor: split(".")[:2] | map(tonumber); + .versions | keys + | map(select(test("^[0-9]+\\.[0-9]+\\.[0-9]+$"))) # releases, not pre-releases + | map(select(minor >= ($oldest | minor))) # from the oldest minor version in use + | group_by(minor) | map(max_by(split(".") | map(tonumber))) | .[] # the newest patch of each + ' +} + +# Downloads Pagefind $1 to $TMP/$1/pagefind. +download_pagefind() { + local dir asset url + dir=$TMP/$1 + case $(uname -s)-$(uname -m) in + Linux-x86_64 | Linux-aarch64) asset="pagefind-v$1-$(uname -m)-unknown-linux-musl.tar.gz" ;; + Darwin-arm64) asset="pagefind-v$1-aarch64-apple-darwin.tar.gz" ;; + Darwin-x86_64) asset="pagefind-v$1-x86_64-apple-darwin.tar.gz" ;; + *) echo "no Pagefind release for $(uname -s) $(uname -m)" >&2; return 1 ;; + esac + url="https://github.com/Pagefind/pagefind/releases/download/v$1/${asset}" + mkdir -p "$dir" + curl -fsSL --retry 3 --max-time 300 "$url" -o "$dir/$asset" + curl -fsSL --retry 3 --max-time 60 "$url.sha256" -o "$dir/$asset.sha256" + if command -v sha256sum > /dev/null; then + (cd "$dir" && sha256sum -c --quiet "$asset.sha256") + else + (cd "$dir" && shasum -a 256 -c --quiet "$asset.sha256") # macOS has shasum instead + fi + tar -xzf "$dir/$asset" -C "$dir" +} + +this_version=$(jq -er .version dist/pagefind/pagefind-entry.json) +check_other_sites "$this_version" +[ "$1" = build ] || exit 0 + +# Through a file, since a failure inside $(...) wouldn't stop the script. +versions_to_copy "$this_version" > "$TMP/versions" +for version in $(< "$TMP/versions"); do + echo "Building a Pagefind ${version} copy at pagefind/v$(minor_version "$version")/" + download_pagefind "$version" + "$TMP/$version/pagefind" --site dist --output-path "dist/pagefind/v$(minor_version "$version")" +done diff --git a/docs-site/src/components/Search.astro b/docs-site/src/components/Search.astro new file mode 100644 index 00000000..e1d1ec84 --- /dev/null +++ b/docs-site/src/components/Search.astro @@ -0,0 +1,103 @@ +--- +// Adds the other Valkey sites' results to Starlight's search box. A stopgap until Pagefind PR #1361 and Starlight PR #4307 +// are released, after which Starlight's `pagefind.mergeIndex` setting can replace the + + diff --git a/docs-site/src/cross-site-search.json b/docs-site/src/cross-site-search.json new file mode 100644 index 00000000..2e462c4d --- /dev/null +++ b/docs-site/src/cross-site-search.json @@ -0,0 +1,5 @@ +{ + "label": "Valkey Admin", + "otherSites": ["https://valkey.io/pagefind/", "https://glide.valkey.io/pagefind/", "https://spring.valkey.io/pagefind/"], + "otherSitesIndexWeight": 0.1 +} From 860c8998b9e96ed18c754a519f92dd9e7a2e1319 Mon Sep 17 00:00:00 2001 From: Daniel Frankcom Date: Thu, 29 Oct 2026 11:09:10 -0700 Subject: [PATCH 2/6] Check that each site's index copy matches this site's Pagefind version Signed-off-by: Daniel Frankcom --- docs-site/scripts/index-copies.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs-site/scripts/index-copies.sh b/docs-site/scripts/index-copies.sh index aeac70a8..eb2ddceb 100755 --- a/docs-site/scripts/index-copies.sh +++ b/docs-site/scripts/index-copies.sh @@ -40,7 +40,7 @@ index_state() { } check_other_sites() { - local this_minor index version missing=() + local this_minor index version copy_version missing=() this_minor=$(minor_version "$1") for index in $OTHER_SITES; do # Check whether the site has any Pagefind index at all. @@ -55,9 +55,8 @@ check_other_sites() { down) missing+=("$index"); continue ;; esac # Check whether the needed version is available. - case $(index_state "${index}v${this_minor}/") in - none | down) missing+=("$index") ;; - esac + copy_version=$(index_state "${index}v${this_minor}/") + [ "$(minor_version "$copy_version")" = "$this_minor" ] || missing+=("$index") done [ "${#missing[@]}" -gt 0 ] || return 0 From 983da7de8b98f4b5d9658f089bcf8a28c3c780d5 Mon Sep 17 00:00:00 2001 From: Daniel Frankcom Date: Thu, 29 Oct 2026 11:09:11 -0700 Subject: [PATCH 3/6] Don't persist checkout credentials in the docs site workflow Signed-off-by: Daniel Frankcom --- .github/workflows/docs-site.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/docs-site.yml b/.github/workflows/docs-site.yml index 41154314..23267f86 100644 --- a/.github/workflows/docs-site.yml +++ b/.github/workflows/docs-site.yml @@ -19,6 +19,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + persist-credentials: false - name: Set up Node.js uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6 with: From d51cabfe33e1f2f39f8159497951566cec40054b Mon Sep 17 00:00:00 2001 From: Daniel Frankcom Date: Fri, 30 Oct 2026 09:34:25 -0700 Subject: [PATCH 4/6] Search again once another site's index merges Signed-off-by: Daniel Frankcom --- docs-site/src/components/Search.astro | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs-site/src/components/Search.astro b/docs-site/src/components/Search.astro index e1d1ec84..a57f4828 100644 --- a/docs-site/src/components/Search.astro +++ b/docs-site/src/components/Search.astro @@ -59,9 +59,23 @@ import sites from "../cross-site-search.json" await pagefind.mergeIndex(bundle, { ranking: pagefindUserConfig.ranking, indexWeight: sites.otherSitesIndexWeight }) // Without this the merged site is missing from the filter. await pagefind.filters() + searchAgain() })) } + // Pagefind doesn't redo a search that finished before a site merged, so its results would leave that site out until + // the query changes. Changing the query and putting it back makes the search box search again. + function searchAgain() { + const input = document.querySelector(`${searchBox} .pagefind-ui__search-input`) + if (!input?.value) return + const { value: query, selectionStart, selectionEnd } = input + input.value = query + " " + input.dispatchEvent(new Event("input")) + input.value = query + input.dispatchEvent(new Event("input")) + input.setSelectionRange(selectionStart, selectionEnd) + } + // Merging downloads from the other sites, so it only starts when the visitor first opens the search box. document.querySelector(searchBox)?.addEventListener("focusin", () => { mergeOtherSites().catch((error) => console.warn("Search: merging the other sites failed", error)) From 3a4d0a0a6e798557692f7ed127e717fca3a99ade Mon Sep 17 00:00:00 2001 From: Daniel Frankcom Date: Fri, 30 Oct 2026 10:13:33 -0700 Subject: [PATCH 5/6] Wait for an IME composition to end before searching again Signed-off-by: Daniel Frankcom --- docs-site/src/components/Search.astro | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs-site/src/components/Search.astro b/docs-site/src/components/Search.astro index a57f4828..42d4682a 100644 --- a/docs-site/src/components/Search.astro +++ b/docs-site/src/components/Search.astro @@ -63,9 +63,19 @@ import sites from "../cross-site-search.json" })) } + // Changing the search box's value during an IME composition breaks the composition. iOS Safari leaves the box stuck + // (WebKit bug 255857), and Chromium can duplicate the composed text. A search that comes due during one waits until + // it ends. + let isComposing = false + let isSearchAgainPending = false + // Pagefind doesn't redo a search that finished before a site merged, so its results would leave that site out until // the query changes. Changing the query and putting it back makes the search box search again. function searchAgain() { + if (isComposing) { + isSearchAgainPending = true + return + } const input = document.querySelector(`${searchBox} .pagefind-ui__search-input`) if (!input?.value) return const { value: query, selectionStart, selectionEnd } = input @@ -81,6 +91,17 @@ import sites from "../cross-site-search.json" mergeOtherSites().catch((error) => console.warn("Search: merging the other sites failed", error)) }, { once: true }) + document.querySelector(searchBox)?.addEventListener("compositionstart", () => { + isComposing = true + }) + document.querySelector(searchBox)?.addEventListener("compositionend", () => { + isComposing = false + if (!isSearchAgainPending) return + isSearchAgainPending = false + // Waits a task in case a browser fires this before the composed text is in the box. + setTimeout(searchAgain) + }) + // Pagefind shows only results matching every ticked site, so ticking two would show nothing. Ticking a site therefore // unticks the others (Pagefind issue #594). document.addEventListener("change", (event) => { From 6bf5b19d27d63d698f658349c2e5cd2452c4bbc2 Mon Sep 17 00:00:00 2001 From: Daniel Frankcom Date: Tue, 3 Nov 2026 11:12:34 -0700 Subject: [PATCH 6/6] Note that index-copies.sh is kept in sync across sites Signed-off-by: Daniel Frankcom --- docs-site/scripts/index-copies.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs-site/scripts/index-copies.sh b/docs-site/scripts/index-copies.sh index eb2ddceb..4a6c5606 100755 --- a/docs-site/scripts/index-copies.sh +++ b/docs-site/scripts/index-copies.sh @@ -8,6 +8,8 @@ # # Both fail if a site that has set up cross-site search has no copy for this build's Pagefind minor version yet. # Redeploying that site usually adds the copy. +# +# Each Valkey site with cross-site search has a copy of this script. Keep the copies in sync. set -euo pipefail case ${1:-} in build | check) ;; *) echo "usage: $0 build|check" >&2; exit 2 ;; esac