119
119
"eclipse-ide/.github" : "Eclipse IDE" ,
120
120
} ;
121
121
122
- const file = new URLSearchParams ( window . location . search ) . get ( 'file' ) ;
122
+ function getFileParameter ( ) {
123
+ const search = new URLSearchParams ( window . location . search ) ;
124
+ return search . get ( 'file' ) ?? ( search . get ( 'f' ) == null ? null : `eclipse-platform/www.eclipse.org-eclipse/master/${ search . get ( 'f' ) } ` ) ;
125
+ }
126
+
127
+ function getMarkdownSearch ( path ) {
128
+ const parts = / e c l i p s e - p l a t f o r m \/ w w w \. e c l i p s e \. o r g - e c l i p s e \/ m a s t e r ( .* ) / . exec ( path ) ;
129
+ if ( parts == null ) {
130
+ return `?file=${ path } ` ;
131
+ }
132
+ return `?f=${ parts [ 1 ] . replace ( / ^ \/ / , '' ) } ` ;
133
+ }
134
+
135
+ function getMarkdownURL ( path ) {
136
+ const parts = / e c l i p s e - p l a t f o r m \/ w w w \. e c l i p s e \. o r g - e c l i p s e \/ m a s t e r ( .* ) / . exec ( path ) ;
137
+ if ( parts == null ) {
138
+ return `${ markdownBase } ${ path } ` ;
139
+ }
140
+ return `${ selfHostedMarkdownBase } ${ parts [ 1 ] . replace ( / ^ \/ / , '' ) } ` ;
141
+ }
142
+
143
+ const file = getFileParameter ( ) ;
123
144
const parts = / (?< org > [ ^ / ] + ) \/ (?< repo > [ ^ / ] + ) \/ (?< branch > [ ^ / ] + ) \/ (?< path > .* ) / . exec ( file ) ;
124
145
const org = parts == null ? '' : parts . groups . org ;
125
146
const repo = parts == null ? '' : parts . groups . repo ;
130
151
const selfHosted = repo == 'www.eclipse.org-eclipse' ;
131
152
const repoName = parts == null ? '' : repoNames [ `${ org } /${ repo } ` ] ;
132
153
133
- const localSiteNavigator = isLocalHost ? `<a href="${ markdownBase } eclipse-platform/www.eclipse.org-eclipse/master/">Eclipse Website Navigator</a>` : '' ;
154
+ const localSiteNavigator = isLocalHost ? `<a href="${ getMarkdownURL ( ' eclipse-platform/www.eclipse.org-eclipse/master/' ) } ">Eclipse Website Navigator</a>` : '' ;
134
155
defaultAside = toElements ( `${ markdownAside } ${ localSiteNavigator } ` ) ;
135
156
136
157
if ( parts != null && parts . groups . path . endsWith ( '.md' ) ) {
@@ -192,7 +213,7 @@ <h2>Table of Contents</h2>
192
213
const parts = / \/ r e p o s \/ (?< org > [ ^ / ] + ) \/ (?< repo > [ ^ / ] + ) \/ c o n t e n t s \/ (?< path > .* ) / . exec ( fileURL . pathname ) ;
193
214
const url = new URL ( window . location ) ;
194
215
url . hash = '' ;
195
- url . search = `?file= ${ parts . groups . org } /${ parts . groups . repo } /${ branch } /${ parts . groups . path } `. replace ( '//' , '/' ) ;
216
+ url . search = getMarkdownSearch ( ` ${ parts . groups . org } /${ parts . groups . repo } /${ branch } /${ parts . groups . path } `. replace ( '//' , '/' ) ) ;
196
217
const label = niceName ( fileName . groups . filename ) ;
197
218
return `<div><a href="${ url } ">${ label } <a/></div>\n` ;
198
219
} ) ;
@@ -272,13 +293,13 @@ <h2>Table of Contents</h2>
272
293
if ( logicalHref . hostname == 'api.github.com' ) {
273
294
const parts = / \/ r e p o s \/ (?< org > [ ^ / ] + ) \/ (?< repo > [ ^ / ] + ) \/ c o n t e n t s \/ (?< path > .* ) / . exec ( logicalHref . pathname ) ;
274
295
if ( parts != null ) {
275
- url . search = `?file= ${ parts . groups . org } /${ parts . groups . repo } /${ branch } /${ parts . groups . path } `;
296
+ url . search = getMarkdownSearch ( ` ${ parts . groups . org } /${ parts . groups . repo } /${ branch } /${ parts . groups . path } `) ;
276
297
a . href = url ;
277
298
}
278
299
} else if ( logicalHref . hostname == 'github.com' ) {
279
300
const parts = / (?< org > [ ^ / ] + ) \/ (?< repo > [ ^ / ] + ) \/ b l o b \/ (?< branch > [ ^ / ] + ) \/ (?< path > .* ) / . exec ( logicalHref . pathname ) ;
280
301
if ( parts != null ) {
281
- url . search = `?file =${ parts . groups . org } /${ parts . groups . repo } /${ parts . groups . branch } /${ parts . groups . path } `;
302
+ url . search = getMarkdownSearch ( ` =${ parts . groups . org } /${ parts . groups . repo } /${ parts . groups . branch } /${ parts . groups . path } `) ;
282
303
a . href = url ;
283
304
}
284
305
}
@@ -298,7 +319,7 @@ <h2>Table of Contents</h2>
298
319
const lastPart = filename == 'index' ? '' : `<li>${ niceName ( filename ) } </li>` ;
299
320
breadcrumb . append ( ...toElements ( `
300
321
<li><a href="${ scriptBase } news/">News</a></li>
301
- <li><a href="${ markdownBase } eclipse-platform/www.eclipse.org-eclipse/master/news/${ version } /index.md">${ version } </a></li>
322
+ <li><a href="${ getMarkdownURL ( ` eclipse-platform/www.eclipse.org-eclipse/master/news/${ version } /index.md` ) } ">${ version } </a></li>
302
323
${ lastPart }
303
324
` ) ) ;
304
325
return true ;
@@ -322,7 +343,8 @@ <h2>Table of Contents</h2>
322
343
let crumbPath = '' ;
323
344
for ( const segment of segments ) {
324
345
crumbPath = ( crumbPath == '/' ? '/' : crumbPath + '/' ) + segment ;
325
- breadcrumb . append ( ...toElements ( `<li><a href="?file=${ org } /${ repo } /${ branch } ${ crumbPath } ">${ segment . length == 0 ? repoName : niceName ( segment . replace ( / \. m d $ / , '' ) ) } </a></li>` ) ) ;
346
+ const href = getMarkdownSearch ( `${ org } /${ repo } /${ branch } ${ crumbPath } ` ) ;
347
+ breadcrumb . append ( ...toElements ( `<li><a href="${ href } ">${ segment . length == 0 ? repoName : niceName ( segment . replace ( / \. m d $ / , '' ) ) } </a></li>` ) ) ;
326
348
}
327
349
}
328
350
0 commit comments