hookshot/docs/_site/main.js
Will Hunt 6e36d73ef6
Fix missing version picker on docs. (#843)
* Fix missing ) for version picker

* Create 843.bugfix
2023-11-15 09:20:42 +00:00

41 lines
1.5 KiB
JavaScript

window.addEventListener("load", () => {
const scrollbox = document.querySelector(".sidebar-scrollbox");
scrollbox.innerHTML = `<div class="version-box"><span>Version: </span></div>${scrollbox.innerHTML}`;
const currentVersion = window.HOOKSHOT_VERSION || 'latest';
const selectElement = document.createElement("select");
fetch("https://api.github.com/repos/matrix-org/matrix-hookshot/releases", {
cache: "force-cache",
}).then(res =>
res.json()
).then(releases => {
selectElement.innerHTML = "";
for (const version of ['latest', ...releases.map(r => r.tag_name).filter(s => s !== "0.1.0" && !s.startsWith("helm-"))]) {
const option = document.createElement("option");
option.innerHTML = version;
selectElement.add(option);
if (currentVersion === version) {
option.setAttribute('selected', '');
}
}
}).catch(ex => {
console.error("Failed to fetch version data", ex);
})
const option = document.createElement("option");
option.innerHTML = 'loading...';
selectElement.add(option);
selectElement.addEventListener('change', (event) => {
const path = [
...window.location.pathname.split('/').slice(0, 2),
event.target.value,
...window.location.pathname.split('/').slice(3),
].join('/');
window.location = `${window.location.origin}${path}`;
});
document.querySelector(".version-box").appendChild(selectElement);
});