Skip to content

Commit 96be946

Browse files
committed
added version selector
1 parent deda0d7 commit 96be946

3 files changed

Lines changed: 90 additions & 1 deletion

File tree

docs/assets/css/styles.css

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,39 @@ article table tbody tr td {
1717
.badge.version-badge .value {
1818
background-color: #fddca1;
1919
color: black;
20+
}
21+
/* Light Mode (Default) */
22+
#version-selector {
23+
background-color: #f6f8fa;
24+
color: #24292f;
25+
border: 1px solid #d0d7de;
26+
border-radius: 6px;
27+
padding: 4px 24px 4px 8px;
28+
font-size: 12px;
29+
font-weight: 600;
30+
cursor: pointer;
31+
appearance: none;
32+
background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2324292f'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
33+
background-repeat: no-repeat;
34+
background-position: right 4px center;
35+
background-size: 16px;
36+
transition: background-color 0.2s, border-color 0.2s;
37+
}
38+
39+
#version-selector:hover {
40+
background-color: #f3f4f6;
41+
border-color: #afb8c1;
42+
}
43+
44+
/* Dark Mode (When html has .dark class) */
45+
html.dark #version-selector {
46+
background-color: #24292f;
47+
color: #ffffff;
48+
border-color: #444c56;
49+
background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
50+
}
51+
52+
html.dark #version-selector:hover {
53+
background-color: #2c333a;
54+
border-color: #768390;
2055
}

docs/assets/js/scripts.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
document.addEventListener("DOMContentLoaded", function() {
2+
const base_url = window.location.pathname.split('/')[1];
3+
const json_url = '/' + base_url + "/versions.json";
4+
const stargazers_element = document.querySelector('header div div:nth-child(3) a');
5+
6+
if (!stargazers_element) {
7+
console.warn("Could not find the stargazers element to attach the version selector.");
8+
return;
9+
}
10+
fetch(json_url)
11+
.then(response => response.json())
12+
.then(data => {
13+
const container = document.createElement("div");
14+
container.style.display = "flex";
15+
container.style.alignItems = "center";
16+
container.style.marginLeft = "12px"; // Space between stars and version
17+
18+
// 2. Create the select element
19+
const select = document.createElement("select");
20+
select.id = "version-selector";
21+
select.style.padding = "4px 8px";
22+
select.style.border = "1px solid #444";
23+
select.style.borderRadius = "6px";
24+
select.style.fontSize = "12px";
25+
select.style.fontWeight = "600";
26+
select.onchange = function() { window.location.href = this.value; };
27+
28+
// 3. Populate options
29+
const currentPath = window.location.pathname;
30+
data.forEach(v => {
31+
const opt = document.createElement("option");
32+
const isLatest = v.aliases.includes("latest");
33+
34+
// If it's the latest, point to the /latest/ alias instead of the version folder
35+
opt.value = isLatest ? `/${base_url}/latest/` : `/${base_url}/${v.version}/`;
36+
37+
opt.textContent = isLatest ? `${v.title} (latest)` : v.title;
38+
39+
if (currentPath.includes(`/${v.version}/`) || (isLatest && currentPath.includes('/latest/'))) {
40+
opt.selected = true;
41+
}
42+
select.appendChild(opt);
43+
});
44+
45+
container.appendChild(select);
46+
47+
stargazers_element.insertAdjacentElement('afterend', container);
48+
})
49+
.catch(error => console.error("Error loading versions:", error));
50+
});

mkdocs.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ plugins:
2121
'configurations/reitti-integration.md': 'integrations/reitti.md'
2222
markdown_extensions:
2323
- codehilite
24-
24+
extra:
25+
version:
26+
provider: mike
27+
extra_javascript:
28+
- assets/js/scripts.js
2529
extra_css:
2630
- assets/css/styles.css

0 commit comments

Comments
 (0)