File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11function 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 }
You can’t perform that action at this time.
0 commit comments