Skip to content

Commit d45d9b6

Browse files
committed
gemini review changes
1 parent 4a5432e commit d45d9b6

File tree

2 files changed

+34
-36
lines changed

2 files changed

+34
-36
lines changed

.hugo/layouts/partials/navbar-version-selector.html

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,48 @@
66
<div w3-include-html="{{ .Site.Params.releases_url }}" w3-include-html-default='<a class="dropdown-item" href="{{ .Site.Params.global_logo_url }}dev/">Dev</a>'></div>
77

88
<script>
9-
w3.includeHTML();
9+
w3.includeHTML(function() {
10+
const basePath = "{{ site.BaseURL | relURL }}";
1011

11-
const basePath = "{{ site.BaseURL | relURL }}";
12+
function stripBase(path) {
13+
if (path.startsWith(basePath)) return path.substring(basePath.length);
14+
if (basePath === "/" && path.startsWith("/")) return path.substring(1);
15+
return path.replace(/^\//, '');
16+
}
1217

13-
function stripBase(path) {
14-
if (path.startsWith(basePath)) return path.substring(basePath.length);
15-
if (basePath === "/" && path.startsWith("/")) return path.substring(1);
16-
return path.replace(/^\//, '');
17-
}
18+
document.getElementById('version-dropdown-menu').addEventListener('click', function(e) {
19+
const link = e.target.closest('a.dropdown-item');
20+
if (!link) return;
21+
e.preventDefault();
1822

19-
document.getElementById('version-dropdown-menu').addEventListener('click', function(e) {
20-
const link = e.target.closest('a.dropdown-item');
21-
if (!link) return;
22-
e.preventDefault();
23+
let targetPath = link.pathname;
24+
if (!targetPath.endsWith('/')) targetPath += '/';
2325

24-
let targetPath = link.pathname;
25-
if (!targetPath.endsWith('/')) targetPath += '/';
26+
let cleanCurrentPath = stripBase(window.location.pathname);
2627

27-
let cleanCurrentPath = stripBase(window.location.pathname);
28+
const allLinks = document.querySelectorAll('#version-dropdown-menu a.dropdown-item');
29+
let currentVersionPrefix = "";
2830

29-
const allLinks = document.querySelectorAll('#version-dropdown-menu a.dropdown-item');
30-
let currentVersionPrefix = "";
31+
allLinks.forEach(a => {
32+
let cleanVPath = stripBase(a.pathname);
33+
if (!cleanVPath.endsWith('/')) cleanVPath += '/';
3134

32-
allLinks.forEach(a => {
33-
let cleanVPath = stripBase(a.pathname);
34-
if (!cleanVPath.endsWith('/')) cleanVPath += '/';
35+
if (cleanVPath !== "" && cleanVPath !== "/" && cleanCurrentPath.startsWith(cleanVPath)) {
36+
if (cleanVPath.length > currentVersionPrefix.length) {
37+
currentVersionPrefix = cleanVPath;
38+
}
39+
}
40+
});
3541

36-
if (cleanVPath !== "" && cleanVPath !== "/" && cleanCurrentPath.startsWith(cleanVPath)) {
37-
if (cleanVPath.length > currentVersionPrefix.length) {
38-
currentVersionPrefix = cleanVPath;
39-
}
40-
}
41-
});
42+
let deepPath = cleanCurrentPath;
43+
if (currentVersionPrefix !== "") {
44+
deepPath = cleanCurrentPath.substring(currentVersionPrefix.length);
45+
}
46+
deepPath = deepPath.replace(/^\//, '');
4247

43-
let deepPath = cleanCurrentPath;
44-
if (currentVersionPrefix !== "") {
45-
deepPath = cleanCurrentPath.substring(currentVersionPrefix.length);
46-
}
47-
deepPath = deepPath.replace(/^\//, '');
48-
49-
// Execute the deep route
50-
window.location.href = targetPath + deepPath;
48+
// Execute the deep route
49+
window.location.href = targetPath + deepPath;
50+
});
5151
});
5252
</script>
5353
</div>

.hugo/static/js/migration-banner.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
document.addEventListener('DOMContentLoaded', function() {
2-
// Trigger your releases dropdown
3-
if (typeof w3 !== 'undefined') { w3.includeHTML(); }
42

53
// Setup CSS for the wrapper and the banner
64
var styleTag = document.createElement('style');
@@ -98,4 +96,4 @@ document.addEventListener('DOMContentLoaded', function() {
9896
var navbarHeight = navbar ? navbar.offsetHeight : 64;
9997
wrapper.style.top = navbarHeight + 'px';
10098
}, 50);
101-
});
99+
});

0 commit comments

Comments
 (0)