Skip to content

Commit 96330ad

Browse files
authored
refactor(docs): version picker left-aligned, Reference dropdown replaced with plain nav links (#177)
The version picker was buried on the right side of the navbar next to search and theme controls, and the Reference nav entry used a per-version dropdown while Guide was a plain link — inconsistent and counterintuitive. ## Changes ### Navbar layout (`_master.tmpl`) - Removed `ms-auto` from `#version-picker-container` — it was already before `#navbar` in DOM order, so dropping the margin pushes it left - Added `flex-grow-1` to `#navbar` so search/theme controls remain right-aligned Result: `[Logo] [v1.1 ▾] [Guide] [API Reference] ——— [Search] [Theme]` ### CI toc.yml generation (`publish-documentation.yml`) - Replaced the "Reference dropdown" step (loop over all versions → `dropdown: true` + `items:`) with two plain links — `Guide` and `API Reference` — both pointing to the latest version - The version picker is now the single source of truth for version selection ### Nav link version sync (`version-switcher.js`) - Added `updateNavLinks(version)` — rewrites `href` on all same-origin navbar `<a>` elements to reflect the active version - Uses `new URL(link.href)` for normalised absolute URL handling - Same-origin guard eliminates any `javascript:` scheme path - Version input validated against `/^\d+(\.\d+)*$/` before any DOM mutation - Extracted `VERSION_PATTERN` constant shared across the module - Called on `window.load` (syncs links to the version in the current URL) and on version-change before navigation ### Static toc.yml placeholder - Added `API Reference` entry (pointing to `1.0/`) to reflect the intended nav structure
1 parent 22bcfef commit 96330ad

4 files changed

Lines changed: 37 additions & 15 deletions

File tree

.github/workflows/publish-documentation.yml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,25 +132,16 @@ jobs:
132132
done
133133
mv /tmp/api-reference.json api-reference/api-reference.json
134134
135-
- name: 'Update toc.yml with Reference dropdown'
135+
- name: 'Update toc.yml with navigation links'
136136
shell: bash
137137
run: |
138138
latest="${{ steps.discover-versions.outputs.latest }}"
139139
{
140140
echo "### YamlMime:TableOfContent"
141141
echo "- name: Guide"
142142
echo " href: ${latest}/guide/introduction.html"
143-
echo "- name: Reference"
144-
echo " dropdown: true"
145-
echo " items:"
146-
for ver in $(echo "${{ steps.discover-versions.outputs.versions }}" | tr ',' '\n' | sort -Vr); do
147-
if [ "$ver" = "$latest" ]; then
148-
echo " - name: v${ver} (latest)"
149-
else
150-
echo " - name: v${ver}"
151-
fi
152-
echo " href: ${ver}/PolylineAlgorithm.html"
153-
done
143+
echo "- name: API Reference"
144+
echo " href: ${latest}/PolylineAlgorithm.html"
154145
} > api-reference/toc.yml
155146
156147
- name: 'Inject latest version and released versions table into index.md'

api-reference/docs-versioning/layout/_master.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@
7171
<i class="bi bi-three-dots"></i>
7272
</button>
7373
<div class="collapse navbar-collapse" id="navpanel">
74-
<div id="version-picker-container" class="ms-auto d-flex align-items-center px-2">
74+
<div id="version-picker-container" class="d-flex align-items-center px-2">
7575
<select id="version-picker" class="form-select form-select-sm" style="width:auto" aria-label="Select version"></select>
7676
</div>
77-
<div id="navbar">
77+
<div id="navbar" class="flex-grow-1">
7878
{{#_enableSearch}}
7979
<form class="search" role="search" id="search">
8080
<i class="bi bi-search"></i>

api-reference/docs-versioning/public/version-switcher.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,29 @@
1616
return meta ? meta.getAttribute('content') : './';
1717
}
1818

19+
var VERSION_PATTERN = /\/\d+(\.\d+)*\//;
20+
21+
function updateNavLinks(version) {
22+
var navbar = document.getElementById('navbar');
23+
if (!navbar || !version) return;
24+
if (!/^\d+(\.\d+)*$/.test(version)) return;
25+
26+
var links = navbar.querySelectorAll('a');
27+
links.forEach(function (link) {
28+
var absUrl;
29+
try {
30+
absUrl = new URL(link.href);
31+
} catch (e) {
32+
return;
33+
}
34+
if (absUrl.origin !== window.location.origin) return;
35+
var newPathname = absUrl.pathname.replace(VERSION_PATTERN, '/' + version + '/');
36+
if (newPathname !== absUrl.pathname) {
37+
link.setAttribute('href', absUrl.origin + newPathname + absUrl.search + absUrl.hash);
38+
}
39+
});
40+
}
41+
1942
function initVersionPicker(versions, latest) {
2043
var select = document.getElementById('version-picker');
2144
if (!select) return;
@@ -42,10 +65,16 @@
4265
select.insertBefore(placeholder, select.firstChild);
4366
}
4467

68+
window.addEventListener('load', function () {
69+
updateNavLinks(currentVersion || latest);
70+
});
71+
4572
select.addEventListener('change', function () {
4673
var targetVersion = select.value;
4774
if (!targetVersion) return;
4875

76+
updateNavLinks(targetVersion);
77+
4978
var newPathname;
5079
if (currentVersion && relativePath) {
5180
newPathname = window.location.pathname.replace(

api-reference/toc.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
### YamlMime:TableOfContent
22
- name: Guide
3-
href: guide/
3+
href: guide/
4+
- name: API Reference
5+
href: 1.0/

0 commit comments

Comments
 (0)