Skip to content
This repository was archived by the owner on Feb 12, 2026. It is now read-only.

Commit 3214de8

Browse files
committed
fixed navbar highlighting
1 parent 2d1fb43 commit 3214de8

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

js/navbar-highlight.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
const currentPath = window.location.pathname.replace(/\/$/, '') || '/';
1+
const normalizePath = (path) => {
2+
return path
3+
.replace(/\/$/, '')
4+
.replace(/\.html$/, '')
5+
|| '/';
6+
};
7+
8+
const currentPath = normalizePath(window.location.pathname);
29

310
document.querySelectorAll('.navbar a').forEach(link => {
411
const href = link.getAttribute('href');
5-
612
if (!href || href === '#') return;
713

8-
const normalizedHref = href.length > 1 ? href.replace(/\/$/, '') : href;
14+
const normalizedHref = normalizePath(href);
915

1016
if (normalizedHref === currentPath) {
1117
link.classList.add('active');

0 commit comments

Comments
 (0)