Skip to content

Commit dcc8e7e

Browse files
kwagyemanclaude
andcommitted
nav-versions: set the switcher button label from the URL
Releases are now a copy of the dev build, so the button's baked label is always 'dev'. Override it client-side from the channel in the URL, so a copied snapshot served at /v5.0.0/ shows 'v5.0.0' with no rewrite of that element. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 495bce0 commit dcc8e7e

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

docs/static/nav-versions.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@
3232
return "/" + p.slice(2).join("/");
3333
}
3434

35+
// The switcher button shows the channel baked at build time (always "dev",
36+
// since releases are a copy of the dev build). Override it from the URL so a
37+
// copied snapshot's button reads its own version ("v5.0.0") with no rewrite.
38+
function setCurrentLabel() {
39+
var box = document.querySelector(".nav-versions");
40+
if (!box) return;
41+
var cur = channelOf(window.location.pathname);
42+
if (!cur) return;
43+
var label = box.querySelector('button span[class~="md:inline"]');
44+
if (label) label.textContent = cur;
45+
}
46+
3547
function populate(data) {
3648
var box = document.querySelector(".nav-versions");
3749
if (!box || !data || !Array.isArray(data.versions)) return;
@@ -68,9 +80,14 @@
6880
.catch(function () { /* offline / local build: keep the server bootstrap */ });
6981
}
7082

83+
function run() {
84+
setCurrentLabel(); // URL-based, works even if versions.json can't be fetched
85+
load();
86+
}
87+
7188
if (document.readyState === "loading") {
72-
document.addEventListener("DOMContentLoaded", load);
89+
document.addEventListener("DOMContentLoaded", run);
7390
} else {
74-
load();
91+
run();
7592
}
7693
})();

0 commit comments

Comments
 (0)