File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -84,14 +84,27 @@ function buildSidebar() {
8484 // skip root index (home) at top level
8585 if ( relPath === '' && name === 'index' ) continue ;
8686
87- // compute link
87+ // compute link (encode each segment to avoid spaces causing Invalid URL)
8888 let link ;
8989 if ( name === 'index' ) {
9090 // directory index becomes the path to folder
91- link = `/${ relPath } /` . replace ( / \\ / g, '/' ) ;
91+ // encode each part of relPath separately
92+ if ( relPath ) {
93+ const parts = relPath . split ( '/' ) . map ( encodeURIComponent ) ;
94+ link = `/${ parts . join ( '/' ) } /` ;
95+ } else {
96+ link = `/` ;
97+ }
9298 } else {
93- link = `/${ relPath } /${ name } ` . replace ( / \\ / g, '/' ) ;
99+ if ( relPath ) {
100+ const parts = relPath . split ( '/' ) . map ( encodeURIComponent ) ;
101+ parts . push ( encodeURIComponent ( name ) ) ;
102+ link = `/${ parts . join ( '/' ) } ` ;
103+ } else {
104+ link = `/${ encodeURIComponent ( name ) } ` ;
105+ }
94106 }
107+ link = link . replace ( / \\ / g, '/' ) ;
95108 items . push ( { text : name , link } ) ;
96109 }
97110
You can’t perform that action at this time.
0 commit comments