docs: add version label to navbar (#186)

Co-authored-by: Elias Schneider <login@eliasschneider.com>
This commit is contained in:
Kyle Mendell
2025-01-28 15:19:16 -06:00
committed by GitHub
parent 77985800ae
commit b530d646ac
2 changed files with 33 additions and 1 deletions

23
docs/src/version-label.ts Normal file
View File

@@ -0,0 +1,23 @@
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";
if (ExecutionEnvironment.canUseDOM) {
function readVersionFile() {
return fetch(
"https://raw.githubusercontent.com/stonith404/pocket-id/refs/heads/main/.version"
)
.then((response) => response.text())
.catch((error) => `Error reading version file: ${error}`);
}
function getVersion() {
readVersionFile()
.then((version) => {
const versionLabels = document.querySelectorAll('[href="#version"]');
versionLabels.forEach((label) => {
(label as HTMLElement).innerText = `v${version}`;
});
})
.catch((error) => console.error("Error fetching version:", error));
}
window.addEventListener("load", getVersion);
}