Skip to content

Commit 4a3c1f0

Browse files
committed
Fix sidebar links on all pages, update nav.js as single source of truth
1 parent 7edf649 commit 4a3c1f0

4 files changed

Lines changed: 19 additions & 27 deletions

File tree

about/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@
4949
</nav>
5050
<div class="layout">
5151
<div class="sidebar-outer">
52-
<div id="site-sidebar">
53-
<a href="../libraries">Libraries</a>
54-
<a href="../reference">Reference</a>
55-
<a href="../examples">Examples</a>
56-
<a href="../about" class="active">About</a>
52+
<div id="site-sidebar">
53+
<a href="../libraries" >Libraries</a>
54+
<a href="../reference" >Reference</a>
55+
<a href="../examples" >Examples</a>
56+
<a href="../about" class='active'>About</a>
5757
</div>
5858
</div>
5959
<div class="content">

assets/nav.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
(function() {
22
const path = window.location.pathname;
3-
4-
// Figure out prefix based on depth
3+
const isRoot = path === '/' || path === '/index.html';
54
const parts = path.replace(/\/$/, '').split('/').filter(Boolean);
6-
const isRoot = parts.length === 0;
7-
const isExamplePage = parts.length === 2 && parts[0] === 'examples';
8-
const prefix = (isRoot) ? '/' : '../';
5+
const prefix = (isRoot || parts.length === 0) ? '/' : '../';
96

10-
// Active link detection
117
function isActive(name) {
128
return path.includes('/' + name);
139
}
@@ -17,23 +13,19 @@
1713
return `<a href="${prefix}${name}"${active}>${label}</a>`;
1814
}
1915

20-
// Inject nav
2116
const nav = document.getElementById('site-nav');
2217
if (nav) {
23-
const logoTag = isRoot
24-
? `<div class="nav-logo">`
25-
: `<a href="${prefix}" class="nav-logo">`;
18+
const logoTag = isRoot ? `<div class="nav-logo">` : `<a href="${prefix}" class="nav-logo">`;
2619
const logoClose = isRoot ? `</div>` : `</a>`;
2720
nav.innerHTML = `
2821
${logoTag}
2922
<img src="${prefix}assets/cpp-logo.png" alt="C++ Mode">
3023
<span>C++ Mode</span>
3124
${logoClose}
32-
<button class="hamburger" onclick="document.querySelector('.sidebar-outer').classList.toggle('open')">☰</button>
25+
<button class="hamburger" onclick="document.querySelector('.sidebar-outer') && document.querySelector('.sidebar-outer').classList.toggle('open')">☰</button>
3326
`;
3427
}
3528

36-
// Inject sidebar top links
3729
const sidebar = document.getElementById('site-sidebar');
3830
if (sidebar) {
3931
sidebar.innerHTML = `

libraries/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@
4949
</nav>
5050
<div class="layout">
5151
<div class="sidebar-outer">
52-
<div id="site-sidebar">
53-
<a href="../libraries" class="active">Libraries</a>
54-
<a href="../reference">Reference</a>
55-
<a href="../examples">Examples</a>
56-
<a href="../about">About</a>
52+
<div id="site-sidebar">
53+
<a href="../libraries" class='active'>Libraries</a>
54+
<a href="../reference" >Reference</a>
55+
<a href="../examples" >Examples</a>
56+
<a href="../about" >About</a>
5757
</div>
5858
</div>
5959
<div class="content">

reference/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@
4949
</nav>
5050
<div class="layout">
5151
<div class="sidebar-outer">
52-
<div id="site-sidebar">
53-
<a href="../libraries">Libraries</a>
54-
<a href="../reference" class="active">Reference</a>
55-
<a href="../examples">Examples</a>
56-
<a href="../about">About</a>
52+
<div id="site-sidebar">
53+
<a href="../libraries" >Libraries</a>
54+
<a href="../reference" class='active'>Reference</a>
55+
<a href="../examples" >Examples</a>
56+
<a href="../about" >About</a>
5757
</div>
5858
</div>
5959
<div class="content">

0 commit comments

Comments
 (0)