Skip to content

Commit a39429b

Browse files
Updated the generateBreadcrumb.js
1 parent c29ff79 commit a39429b

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

assets/js/generateBreadcrumb.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,42 @@
11
function generateBreadCrumb() {
22
const breadCrumbContainer = document.getElementById("breadcrumb");
3+
4+
// Get path parts
35
let pathArray = window.location.pathname.split("/").filter((p) => p);
46

5-
const repoName = "javascript-course-notes";
7+
const repoName = pathArray.length > 0 ? pathArray[0] : "";
68
const basePath = `/${repoName}`;
79

10+
// Drop the repo name so breadcrumb starts clean
11+
if (repoName) {
12+
pathArray.shift();
13+
}
14+
815
// If last segment is index.html, drop it
916
if (pathArray[pathArray.length - 1]?.toLowerCase() === "index.html") {
1017
pathArray.pop();
1118
}
1219

20+
// Start breadcrumb with home icon
1321
let breadcrumbHTML = `
1422
<a href="${basePath}/index.html">
1523
<img src="${basePath}/assets/Icons/monitor.png" style="width: 30px;"/>
1624
</a>
17-
<img src="${basePath}/assets/Icons/arrow_right.png" style="width: 20px; height: 20px;"/>
1825
`;
1926

2027
let fullPath = "";
2128
pathArray.forEach((segment, index) => {
2229
fullPath += `/${segment}`;
2330
const isLast = index === pathArray.length - 1;
2431

32+
breadcrumbHTML += `
33+
<img src="${basePath}/assets/Icons/arrow_right.png" style="width: 20px; height: 20px;"/>
34+
`;
35+
2536
if (!isLast) {
2637
breadcrumbHTML += `<a href="${basePath}${fullPath}">${decodeURIComponent(
2738
segment
28-
)}</a>
29-
<img src="${basePath}/assets/Icons/arrow_right.png" style="width: 20px; height: 20px;"/>`;
39+
)}</a>`;
3040
} else {
3141
breadcrumbHTML += `<span>${decodeURIComponent(segment)}</span>`;
3242
}

0 commit comments

Comments
 (0)