1- const pages = [
2- { title : "Overview" , href : "pages/overview.html" } ,
3- { title : "Service Definition" , href : "pages/service-definition.html" } ,
4- { title : "Operating Model" , href : "pages/operating-model.html" } ,
5- { title : "Architecture" , href : "pages/architecture.html" } ,
6- { title : "KPIs" , href : "pages/kpis.html" } ,
7- { title : "Roadmap" , href : "pages/roadmap.html" } ,
8- { title : "Runbooks" , href : "pages/runbooks.html" } ,
9- { title : "Templates" , href : "pages/templates.html" } ,
10- { title : "Hybrid" , href : "pages/hybrid.html" }
1+ const pageDefinitions = [
2+ { title : "Overview" , path : "pages/overview.html" } ,
3+ { title : "Service Definition" , path : "pages/service-definition.html" } ,
4+ { title : "Operating Model" , path : "pages/operating-model.html" } ,
5+ { title : "Architecture" , path : "pages/architecture.html" } ,
6+ { title : "KPIs" , path : "pages/kpis.html" } ,
7+ { title : "Roadmap" , path : "pages/roadmap.html" } ,
8+ { title : "Runbooks" , path : "pages/runbooks.html" } ,
9+ { title : "Templates" , path : "pages/templates.html" } ,
10+ { title : "Hybrid" , path : "pages/hybrid.html" }
1111] ;
1212
13+ function getBasePath ( ) {
14+ let path = window . location . pathname ;
15+ if ( path . endsWith ( "/" ) ) {
16+ path = path . slice ( 0 , - 1 ) ;
17+ }
18+ if ( path . endsWith ( "/index.html" ) ) {
19+ path = path . slice ( 0 , - "/index.html" . length ) ;
20+ }
21+ if ( path . includes ( "/pages/" ) ) {
22+ path = path . split ( "/pages/" ) [ 0 ] ;
23+ }
24+ return path || "" ;
25+ }
26+
27+ function resolveHref ( targetPath ) {
28+ const basePath = getBasePath ( ) ;
29+ const trimmedBase = basePath . replace ( / \/ $ / , "" ) ;
30+ return `${ trimmedBase } /${ targetPath } ` ;
31+ }
32+
1333function buildNav ( ) {
1434 const nav = document . getElementById ( "nav-links" ) ;
15- pages . forEach ( ( page ) => {
35+ pageDefinitions . forEach ( ( page ) => {
1636 const link = document . createElement ( "a" ) ;
17- link . href = page . href ;
37+ link . href = resolveHref ( page . path ) ;
1838 link . textContent = page . title ;
1939 nav . appendChild ( link ) ;
2040 } ) ;
@@ -25,14 +45,14 @@ function setupSearch() {
2545 if ( ! input ) return ;
2646 input . addEventListener ( "input" , ( event ) => {
2747 const query = event . target . value . toLowerCase ( ) ;
28- const results = pages . filter ( ( page ) =>
48+ const results = pageDefinitions . filter ( ( page ) =>
2949 page . title . toLowerCase ( ) . includes ( query )
3050 ) ;
3151 const nav = document . getElementById ( "nav-links" ) ;
3252 nav . innerHTML = "" ;
3353 results . forEach ( ( page ) => {
3454 const link = document . createElement ( "a" ) ;
35- link . href = page . href ;
55+ link . href = resolveHref ( page . path ) ;
3656 link . textContent = page . title ;
3757 nav . appendChild ( link ) ;
3858 } ) ;
0 commit comments