-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmains.js
42 lines (35 loc) · 1.15 KB
/
mains.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//generateBreadcrumbs
const currentPage = window.location.pathname;
const pageNames = {
"/": "home",
"/posts/post.html": "posts",
"/about/about.html": "about",
"/posts/blog1.html": "welcome",
"/posts/blog2.html": "cicada 3301",
"/posts/blog3.html": "the big O",
"/posts/blog4.html": "delusion",
"/posts/blog5.html": "chronicle",
"/posts/blog6.html": "learning curve",
};
function generateBreadcrumbs() {
const breadcrumbContainer = document.querySelector(".breadcrumbs");
if (!breadcrumbContainer) {
console.error("Breadcrumb container not found.");
return;
}
const pathSegments = currentPage.split("/").filter(Boolean);
let breadcrumbPath = '<a href="/">home</a>';
pathSegments.reduce((acc, segment, index) => {
const path = `/${pathSegments.slice(0, index + 1).join("/")}`;
const pageName = pageNames[path];
if (pageName) {
if (path.startsWith("/posts/blog")) {
breadcrumbPath += ' / <a href="/posts/post.html">posts</a>';
}
breadcrumbPath += ` / <a href="${path}">${pageName}</a>`;
}
return path;
}, "");
breadcrumbContainer.innerHTML = breadcrumbPath;
}
generateBreadcrumbs();