diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2025-10-11 11:08:32 -0400 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2025-10-11 11:08:32 -0400 |
| commit | 3cd15cb2e3aecc4c2e1e553d9ac7e4a7a67c46b1 (patch) | |
| tree | 02db3787a0adc0a094611de91490da33581c837c /docs/js | |
| parent | Adjust index.md to fix formatting of installation (diff) | |
| download | cli-3cd15cb2e3aecc4c2e1e553d9ac7e4a7a67c46b1.zip | |
Add support for versioned docs
Diffstat (limited to 'docs/js')
| -rw-r--r-- | docs/js/version-selector.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/docs/js/version-selector.js b/docs/js/version-selector.js new file mode 100644 index 0000000..fb0a187 --- /dev/null +++ b/docs/js/version-selector.js @@ -0,0 +1,39 @@ +(function () { + fetch("/versions.json") + .then((r) => r.json()) + .then((data) => { + const currentPath = window.location.pathname; + const pathParts = currentPath.split("/").filter((p) => p); + const currentVersion = pathParts[0] || "latest"; + + const header = document.querySelector(".md-header__inner"); + if (!header) return; + + const select = document.createElement("select"); + select.className = "md-version-select"; + select.style.cssText = + "margin-left: 1rem; padding: 0.25rem 0.5rem; border-radius: 0.25rem; background: var(--md-default-bg-color); border: 1px solid var(--md-default-fg-color--lighter);"; + + data.versions.forEach((v) => { + const option = document.createElement("option"); + option.value = v.version; + option.textContent = v.title; + if (v.version === currentVersion) { + option.selected = true; + } + select.appendChild(option); + }); + + select.addEventListener("change", (e) => { + const newVersion = e.target.value; + const remainingPath = pathParts.slice(1).join("/"); + window.location.href = + "/" + newVersion + (remainingPath ? "/" + remainingPath : "/"); + }); + + header.appendChild(select); + }) + .catch((err) => { + console.error("Failed to load version selector:", err); + }); +})(); |