Skip to content

Commit d59c1f7

Browse files
committed
Fix navigation links: correct relative paths for pages directory
1 parent 3268e0e commit d59c1f7

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

js/main.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ async function loadComponents() {
7676
*/
7777
function updateHeaderLinks(basePath) {
7878
const isInPages = basePath === "../";
79-
const pagesPrefix = isInPages ? "" : "pages/";
8079

8180
// Update logo
8281
const logoLink = document.getElementById("nav-logo-link");
@@ -91,7 +90,13 @@ function updateHeaderLinks(basePath) {
9190
if (page === "index") {
9291
link.href = `${basePath}index.html`;
9392
} else {
94-
link.href = `${basePath}${pagesPrefix}${page}.html`;
93+
// If we're in the pages directory, other pages are in the same directory
94+
// If we're at root, pages are in the pages/ subdirectory
95+
if (isInPages) {
96+
link.href = `./${page}.html`;
97+
} else {
98+
link.href = `./pages/${page}.html`;
99+
}
95100
}
96101
});
97102
}
@@ -101,7 +106,6 @@ function updateHeaderLinks(basePath) {
101106
*/
102107
function updateFooterLinks(basePath) {
103108
const isInPages = basePath === "../";
104-
const pagesPrefix = isInPages ? "" : "pages/";
105109

106110
// Update logo
107111
const logoLink = document.getElementById("footer-logo-link");
@@ -113,7 +117,13 @@ function updateFooterLinks(basePath) {
113117
const footerLinks = document.querySelectorAll(".footer-links a[data-page]");
114118
footerLinks.forEach((link) => {
115119
const page = link.getAttribute("data-page");
116-
link.href = `${basePath}${pagesPrefix}${page}.html`;
120+
// If we're in the pages directory, other pages are in the same directory
121+
// If we're at root, pages are in the pages/ subdirectory
122+
if (isInPages) {
123+
link.href = `./${page}.html`;
124+
} else {
125+
link.href = `./pages/${page}.html`;
126+
}
117127
});
118128
}
119129

0 commit comments

Comments
 (0)