2022-10-21 15:39:00 +00:00
|
|
|
<div class="versions_menu">
|
|
|
|
<div class="versions_menu__header">
|
2022-12-12 13:31:00 +00:00
|
|
|
<span id="versions_menu-current-version"></span>
|
|
|
|
<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>
|
|
|
|
<!-- Current Version -->
|
2022-10-21 15:39:00 +00:00
|
|
|
</div>
|
|
|
|
<div class="versions_menu__content">
|
|
|
|
<span>Versions</span>
|
2022-12-12 13:31:00 +00:00
|
|
|
<ul class="versions_menu__list">
|
|
|
|
<!-- Versions list -->
|
|
|
|
</ul>
|
2022-10-21 15:39:00 +00:00
|
|
|
</div>
|
|
|
|
<style>
|
|
|
|
.versions_menu {
|
|
|
|
position: fixed;
|
|
|
|
bottom: 0;
|
|
|
|
right: 30px;
|
2022-12-12 13:31:00 +00:00
|
|
|
font-family: var(--font-stack, -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji);
|
2022-10-21 15:39:00 +00:00
|
|
|
border: 1px solid var(--color-background-border, #eeebee);
|
|
|
|
z-index: 98;
|
|
|
|
}
|
|
|
|
|
|
|
|
.versions_menu__header {
|
2022-12-12 13:31:00 +00:00
|
|
|
display: flex;
|
2022-10-21 15:39:00 +00:00
|
|
|
padding: 8px 10px;
|
|
|
|
font-size: 14px;
|
|
|
|
border-bottom: 1px solid var(--color-background-border, #eeebee);
|
|
|
|
background-color: var(--color-background-secondary, #f8f9fb);
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
2022-12-12 13:31:00 +00:00
|
|
|
|
2022-10-21 15:39:00 +00:00
|
|
|
.versions_menu__header:hover {
|
|
|
|
background-color: var(--color-background-hover, #efeff4);
|
|
|
|
}
|
|
|
|
|
2022-12-12 13:31:00 +00:00
|
|
|
.versions_menu__header span {
|
|
|
|
display: flex;
|
|
|
|
flex: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
.versions_menu__header svg {
|
|
|
|
transform: rotate(-90deg);
|
|
|
|
}
|
|
|
|
|
|
|
|
.versions_menu.active .versions_menu__header svg {
|
|
|
|
transform: rotate(90deg);
|
|
|
|
}
|
|
|
|
|
2022-10-21 15:39:00 +00:00
|
|
|
.versions_menu__content {
|
|
|
|
width: 200px;
|
|
|
|
max-height: 0;
|
|
|
|
transition: max-height 0.5s ease-in-out;
|
|
|
|
background-color: var(--color-background-primary, #fff);
|
|
|
|
box-sizing: border-box;
|
|
|
|
}
|
2022-12-12 13:31:00 +00:00
|
|
|
|
|
|
|
.versions_menu.active .versions_menu__content {
|
2022-10-21 15:39:00 +00:00
|
|
|
max-height: 200px;
|
|
|
|
}
|
2022-12-12 13:31:00 +00:00
|
|
|
|
2022-10-21 15:39:00 +00:00
|
|
|
.versions_menu__content span {
|
|
|
|
display: block;
|
|
|
|
padding: 8px 10px;
|
|
|
|
font-size: 12px;
|
|
|
|
text-transform: uppercase;
|
|
|
|
color: var(--color-foreground-muted, #646776);
|
|
|
|
}
|
2022-12-12 13:31:00 +00:00
|
|
|
|
2022-10-21 15:39:00 +00:00
|
|
|
.versions_menu__list {
|
|
|
|
list-style: none;
|
|
|
|
padding: 0 8px 8px;
|
|
|
|
margin: 0;
|
|
|
|
}
|
2022-12-12 13:31:00 +00:00
|
|
|
|
|
|
|
.versions_menu__list li {}
|
|
|
|
|
2022-10-21 15:39:00 +00:00
|
|
|
.versions_menu__list li a {
|
|
|
|
display: block;
|
|
|
|
padding: 4px 10px;
|
|
|
|
font-size: 14px;
|
2023-03-24 17:29:47 +00:00
|
|
|
color: var(--color-link, #2962ff);
|
2022-10-21 15:39:00 +00:00
|
|
|
text-decoration: none;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
2022-12-12 13:31:00 +00:00
|
|
|
|
2022-10-21 15:39:00 +00:00
|
|
|
.versions_menu__list li:hover {
|
|
|
|
background-color: var(--color-background-hover, #efeff4)
|
|
|
|
}
|
2022-12-12 13:31:00 +00:00
|
|
|
@media screen and (max-width: 400px) {
|
|
|
|
.versions_menu__content {
|
|
|
|
width: 140px;
|
|
|
|
}
|
|
|
|
}
|
2022-10-21 15:39:00 +00:00
|
|
|
</style>
|
|
|
|
<script>
|
|
|
|
const githubUser = versioningConfig.githubUser;
|
|
|
|
const repo = versioningConfig.githubRepo;
|
|
|
|
|
2022-12-12 13:31:00 +00:00
|
|
|
const menuElem = document.querySelector(".versions_menu");
|
2022-10-21 15:39:00 +00:00
|
|
|
const headerElem = document.querySelector(".versions_menu__header");
|
2022-12-12 13:31:00 +00:00
|
|
|
const versionElemList = document.querySelector(".versions_menu__list");
|
|
|
|
|
|
|
|
headerElem.onclick = (e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
if (menuElem.classList.contains("active")) {
|
|
|
|
menuElem.classList.remove("active");
|
2022-10-21 15:39:00 +00:00
|
|
|
} else {
|
2022-12-12 13:31:00 +00:00
|
|
|
menuElem.classList.add("active");
|
2022-10-21 15:39:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-12 13:31:00 +00:00
|
|
|
document.addEventListener("click", () => {
|
|
|
|
menuElem.classList.remove("active");
|
|
|
|
});
|
|
|
|
|
2023-01-20 14:42:12 +00:00
|
|
|
const sortVersions = (a, b) => {
|
|
|
|
if (a.replace("v", "") > b.replace("v", ""))
|
|
|
|
return -1
|
|
|
|
else if (a.replace("v", "") < b.replace("v", ""))
|
|
|
|
return 1
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2023-07-14 22:50:55 +00:00
|
|
|
if ((githubUser !== null && githubUser !== "") || (repo !== null && repo !== "")) {
|
2022-10-21 15:39:00 +00:00
|
|
|
const basePath = "";
|
|
|
|
const mainBranchName = "main"
|
|
|
|
const apiUrl = `https://api.github.com/repos/${githubUser}/${repo}/git/trees/gh-pages`;
|
|
|
|
const versionRegex = new RegExp(/[vV]?\d+\.\d+(\.?\d+)*/);
|
|
|
|
fetch(apiUrl).then(response => {
|
|
|
|
if (response.status !== 200) {
|
|
|
|
console.warn("Unable to load repository tree, the repository must be public", response);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
response.json().then(json => {
|
|
|
|
const versions = json.tree.filter(v => versionRegex.test(v.path)).map(v => v.path);
|
2023-01-20 14:42:12 +00:00
|
|
|
versions.sort(sortVersions);
|
2022-10-21 15:39:00 +00:00
|
|
|
// verify if exists a directory with main version
|
|
|
|
if (json.tree.filter(v => v.path == mainBranchName).length > 0) {
|
|
|
|
versions.unshift(mainBranchName);
|
|
|
|
}
|
2022-12-12 13:31:00 +00:00
|
|
|
|
|
|
|
// Get current path
|
|
|
|
let currentPath = document.location.href.split(document.location.origin)[1];
|
|
|
|
let currentVersion = "";
|
|
|
|
// https://domain.com/basePath/1.2.0/content/index.html -> /1.2.0/content/index.html
|
|
|
|
if (basePath !== "") {
|
|
|
|
currentPath = currentPath.split(basePath).slice(1).join("/");
|
|
|
|
}
|
|
|
|
// /v1.2.0/content/index.html -> /content/index.html
|
|
|
|
if (versionRegex.test(currentPath.split("/")[1]) || currentPath.split("/")[1] === mainBranchName) {
|
|
|
|
currentVersion = currentPath.split("/")[1];
|
|
|
|
currentPath = "/" + currentPath.split("/").slice(2).join("/");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create versions list
|
|
|
|
const listElems = [];
|
|
|
|
let latestVersion = "";
|
2022-10-21 15:39:00 +00:00
|
|
|
for (const version of versions) {
|
|
|
|
const liElem = document.createElement("li");
|
|
|
|
const aElem = document.createElement("a");
|
|
|
|
|
2022-12-12 13:31:00 +00:00
|
|
|
if (version === mainBranchName) {
|
|
|
|
aElem.textContent = version + " (unstable)";
|
|
|
|
} else {
|
|
|
|
if (latestVersion === "") {
|
|
|
|
latestVersion = version;
|
|
|
|
aElem.textContent = latestVersion + " (latest)";
|
|
|
|
} else {
|
|
|
|
aElem.textContent = version;
|
|
|
|
}
|
2022-10-21 15:39:00 +00:00
|
|
|
}
|
|
|
|
|
2022-12-12 13:31:00 +00:00
|
|
|
aElem.href = version === latestVersion ?
|
|
|
|
`${basePath}${currentPath}` :
|
|
|
|
`${basePath}/${version}${currentPath}`;
|
2022-10-21 15:39:00 +00:00
|
|
|
liElem.appendChild(aElem);
|
2022-12-12 13:31:00 +00:00
|
|
|
listElems.push(liElem);
|
|
|
|
versionElemList.appendChild(liElem);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set current version to menu header
|
|
|
|
currentVersionStr = currentVersion || latestVersion;
|
|
|
|
if (currentVersionStr === mainBranchName) {
|
|
|
|
currentVersionStr = currentVersionStr + " (unstable)";
|
|
|
|
} else if (currentVersionStr === latestVersion) {
|
|
|
|
currentVersionStr = currentVersionStr + " (latest)";
|
2022-10-21 15:39:00 +00:00
|
|
|
}
|
2022-12-12 13:31:00 +00:00
|
|
|
document.getElementById("versions_menu-current-version").innerHTML = currentVersionStr;
|
2022-10-21 15:39:00 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
console.error("Invalid versioning configuration");
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</div>
|