|
1 | 1 | function generateBreadCrumb() { |
2 | 2 | const breadCrumbContainer = document.getElementById("breadcrumb"); |
3 | 3 |
|
| 4 | + // Get current path or use simulated path |
| 5 | + let currentPath = window.simulatedPath || window.location.pathname; |
| 6 | + |
4 | 7 | // Split the pathname into parts |
5 | | - let pathArray = window.location.pathname.split("/").filter((p) => p); |
| 8 | + let pathArray = currentPath |
| 9 | + .split("/") |
| 10 | + .filter((p) => p && p.toLowerCase() !== "index.html"); |
6 | 11 |
|
7 | 12 | // Detect repo name (first segment) |
8 | 13 | const repoName = pathArray.length > 0 ? pathArray[0] : ""; |
9 | | - const basePath = `/${repoName}`; |
| 14 | + const basePath = repoName ? `/${repoName}` : ""; |
10 | 15 |
|
11 | 16 | // Remove repo name from breadcrumb segments |
12 | 17 | if (repoName) { |
13 | 18 | pathArray.shift(); |
14 | 19 | } |
15 | 20 |
|
16 | | - // If last segment is index.html, drop it |
17 | | - if (pathArray[pathArray.length - 1]?.toLowerCase() === "index.html") { |
18 | | - pathArray.pop(); |
19 | | - } |
20 | | - |
21 | | - // Start breadcrumb with monitor icon (always links to repo root index.html) |
| 21 | + // Start breadcrumb with home icon (always links to repo root index.html) |
22 | 22 | let breadcrumbHTML = ` |
23 | | - <a href="${basePath}/index.html"> |
24 | | - <img src="${basePath}/assets/Icons/monitor.png" style="width: 30px;"/> |
25 | | - </a> |
26 | | - `; |
| 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 | + `; |
27 | 27 |
|
28 | | - let fullPath = ""; |
| 28 | + let accumulatedPath = basePath; |
| 29 | + |
| 30 | + // Generate breadcrumb segments |
29 | 31 | pathArray.forEach((segment, index) => { |
30 | | - fullPath += `/${segment}`; |
31 | | - const isLast = index === pathArray.length - 1; |
| 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;" />`; |
32 | 34 |
|
33 | | - // Add arrow only if it's not the last segment |
34 | | - breadcrumbHTML += isLast |
35 | | - ? " " |
36 | | - : `<img src="${basePath}/assets/Icons/arrow_right.png" style="width: 20px; height: 20px;"/>`; |
| 35 | + accumulatedPath += `/${segment}`; |
| 36 | + const isLast = index === pathArray.length - 1; |
37 | 37 |
|
38 | 38 | if (!isLast) { |
39 | | - breadcrumbHTML += `<a href="${basePath}${fullPath}">${decodeURIComponent( |
| 39 | + breadcrumbHTML += `<a href="${accumulatedPath}">${decodeURIComponent( |
40 | 40 | segment |
41 | 41 | )}</a>`; |
42 | 42 | } else { |
43 | | - breadcrumbHTML += `<span>${decodeURIComponent(segment)}</span>`; |
| 43 | + // For the last segment, remove .html if present |
| 44 | + const displayName = segment.replace(/\.(html|php|aspx)$/i, ""); |
| 45 | + breadcrumbHTML += `<span>${decodeURIComponent(displayName)}</span>`; |
44 | 46 | } |
45 | 47 | }); |
46 | 48 |
|
|
0 commit comments