Skip to content

Commit 4066302

Browse files
Fixed the issues with breadcrumb generator
1 parent 4368cd0 commit 4066302

File tree

2 files changed

+21
-39
lines changed

2 files changed

+21
-39
lines changed

Courses/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ <h1 class="page-title">Courses</h1>
1616
<div class="courses-cards grid grid--3-cols">
1717
<!-- card 1 -->
1818

19-
<a href="/Courses/JavaScript/index.html" class="courses-card">
19+
<a href="JavaScript/index.html" class="courses-card">
2020
<img
2121
class="card-img"
2222
src="../assets/Images/Courses Banner/JavaScript.jpg"

assets/js/generateBreadcrumb.js

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,32 @@
11
function generateBreadCrumb() {
22
const breadCrumbContainer = document.getElementById("breadcrumb");
3+
let pathArray = window.location.pathname.split("/").filter((p) => p);
4+
const repoName = "javascript-course-notes";
35

4-
// Get current path or use simulated path
5-
let currentPath = window.simulatedPath || window.location.pathname;
6-
7-
// Split the pathname into parts
8-
let pathArray = currentPath
9-
.split("/")
10-
.filter((p) => p && p.toLowerCase() !== "index.html");
11-
12-
// Detect repo name (first segment)
13-
const repoName = pathArray.length > 0 ? pathArray[0] : "";
14-
const basePath = repoName ? `/${repoName}` : "";
15-
16-
// Remove repo name from breadcrumb segments
17-
if (repoName) {
18-
pathArray.shift();
6+
// If last segment is index.html, drop it
7+
if (pathArray[pathArray.length - 1]?.toLowerCase() === "index.html") {
8+
pathArray.pop();
199
}
2010

21-
// Start breadcrumb with home icon (always links to repo root index.html)
2211
let breadcrumbHTML = `
23-
<a href="${basePath}/index.html" title="Home">
24-
<img src="${basePath}/assets/Icons/monitor.png" alt="Home" style="width: 24px; height: 24px;"/>
25-
</a>
26-
`;
12+
<a href="/index.html">
13+
<img src="${repoName}/assets/Icons/monitor.png" style="width: 30px;"/>
14+
</a>
15+
<img src="${repoName}/assets/Icons/arrow_right.png" style="width: 20px; height: 20px;"/>
16+
`;
2717

28-
let accumulatedPath = basePath;
29-
30-
// Generate breadcrumb segments
18+
let fullPath = "";
3119
pathArray.forEach((segment, index) => {
32-
// Add arrow before each segment (except first one which is handled by home icon)
33-
breadcrumbHTML += `<img src="${basePath}/assets/Icons/arrow_right.png" alt="→" style="width: 16px; height: 16px; margin: 0 10px;" />`;
34-
35-
accumulatedPath += `/${segment}`;
36-
const isLast = index === pathArray.length - 1;
37-
38-
if (!isLast) {
39-
breadcrumbHTML += `<a href="${accumulatedPath}">${decodeURIComponent(
40-
segment
41-
)}</a>`;
42-
} else {
43-
// For the last segment, remove .html if present
44-
const displayName = segment.replace(/\.(html|php|aspx)$/i, "");
45-
breadcrumbHTML += `<span>${decodeURIComponent(displayName)}</span>`;
46-
}
20+
if (segment === repoName) return;
21+
fullPath += `/${segment}`;
22+
23+
breadcrumbHTML += `
24+
25+
`;
26+
breadcrumbHTML += `<a href="${fullPath}">${decodeURIComponent(segment)}</a>
27+
<img src="${repoName}/assets/Icons/arrow_right.png" style="width: 20px; height: 20px;"/>`;
4728
});
29+
console.log(fullPath);
4830

4931
breadCrumbContainer.innerHTML = breadcrumbHTML;
5032
}

0 commit comments

Comments
 (0)