@@ -160,6 +160,18 @@ <h2>Table of Contents</h2>
160
160
return hash . toLowerCase ( ) ;
161
161
}
162
162
163
+ function toSiteURL ( url ) {
164
+ if ( url . hostname == 'api.github.com' && url . pathname . startsWith ( '/repos/eclipse-platform/www.eclipse.org-eclipse/contents' ) ) {
165
+ const result = new URL ( window . location ) ;
166
+ result . pathname = url . pathname . replace ( / \/ r e p o s \/ 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 \/ c o n t e n t s / , '/eclipse' )
167
+ result . hash = url . hash ;
168
+ result . search = url . search ;
169
+ return result ;
170
+ } else {
171
+ return null ;
172
+ }
173
+ }
174
+
163
175
function generateFileList ( files ) {
164
176
const fileElements = files . map ( file => {
165
177
const fileURL = new URL ( file . url ) ;
@@ -212,8 +224,18 @@ <h2>Table of Contents</h2>
212
224
const imgs = targetElement . querySelectorAll ( "img[src]" ) ;
213
225
for ( const img of imgs ) {
214
226
const src = img . getAttribute ( 'src' ) ;
227
+ if ( src == null ) {
228
+ continue ;
229
+ }
230
+
215
231
if ( ! src . startsWith ( 'http' ) ) {
216
- img . src = `https://raw.githubusercontent.com/${ org } /${ repo } /${ branch } /${ src } ` ;
232
+ const logicalSrc = new URL ( src , logicalBaseURL ) ;
233
+ const siteURL = toSiteURL ( logicalSrc ) ;
234
+ if ( siteURL != null ) {
235
+ img . src = siteURL ;
236
+ } else {
237
+ img . src = `https://raw.githubusercontent.com/${ org } /${ repo } /${ branch } /${ src } ` ;
238
+ }
217
239
}
218
240
}
219
241
@@ -230,6 +252,14 @@ <h2>Table of Contents</h2>
230
252
}
231
253
232
254
const logicalHref = new URL ( href , logicalBaseURL ) ;
255
+ if ( ! logicalHref . pathname . endsWith ( '.md' ) ) {
256
+ const siteURL = toSiteURL ( logicalHref ) ;
257
+ if ( siteURL != null ) {
258
+ a . href = siteURL ;
259
+ }
260
+ continue ;
261
+ }
262
+
233
263
const url = new URL ( window . location ) ;
234
264
url . hash = fixHash ( logicalHref . hash ) ;
235
265
if ( logicalHref . hostname == 'api.github.com' ) {
0 commit comments