|
1 | 1 | function generateBreadCrumb() { |
2 | 2 | const breadCrumbContainer = document.getElementById("breadcrumb"); |
| 3 | + let pathArray = window.location.pathname.split("/").filter((p) => p); |
| 4 | + const repoName = "javascript-course-notes"; |
3 | 5 |
|
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(); |
19 | 9 | } |
20 | 10 |
|
21 | | - // Start breadcrumb with home icon (always links to repo root index.html) |
22 | 11 | 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 | + `; |
27 | 17 |
|
28 | | - let accumulatedPath = basePath; |
29 | | - |
30 | | - // Generate breadcrumb segments |
| 18 | + let fullPath = ""; |
31 | 19 | 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;"/>`; |
47 | 28 | }); |
| 29 | + console.log(fullPath); |
48 | 30 |
|
49 | 31 | breadCrumbContainer.innerHTML = breadcrumbHTML; |
50 | 32 | } |
|
0 commit comments