@@ -21,10 +21,12 @@ popped = 'state' in window.history;
21
21
initialURL = location . href ;
22
22
23
23
const baseURLPrefix = ( ( ) => {
24
- const scripts = document . getElementsByTagName ( 'script' ) ;
25
- const index = scripts . length - 1 ;
26
- const thisScript = scripts [ index ] ;
27
- return thisScript . src . replace ( / ^ .* : \/ \/ [ ^ / ] * ( .* \/ ) ( a s s e t s | j s ) \/ [ ^ / ] + .j s ( \? .* ) ? $ / , '$1' ) ;
24
+ const thisScriptSrc =
25
+ Array . from ( document . getElementsByTagName ( 'script' ) )
26
+ . pop ( )
27
+ . getAttribute ( 'src' ) ;
28
+ return thisScriptSrc
29
+ . replace ( / ^ (?: [ a - z ] * : \/ \/ [ ^ / ] * ) ? ( .* \/ ) ( a s s e t s | j s ) \/ [ ^ / ] + .j s ( \? .* ) ? $ / , '$1' ) ;
28
30
} ) ( ) ;
29
31
30
32
$ ( document ) . ready ( function ( ) {
@@ -338,7 +340,15 @@ var Search = {
338
340
return ;
339
341
}
340
342
( async ( ) => {
341
- Search . pagefind = await import ( `${ baseURLPrefix } pagefind/pagefind.js` ) ;
343
+ const pagefindURL =
344
+ `${ baseURLPrefix } pagefind/pagefind.js`
345
+ // adjust the `baseURLPrefix` if it is relative: the `import`
346
+ // is relative to the _script URL_ here, which is in /js/.
347
+ // That is different from other uses of `baseURLPrefix`, which
348
+ // replace `href` and `src` attributes which are relative to the
349
+ // page itself that is outside of /js/.
350
+ . replace ( / ^ \. \/ / , '../' )
351
+ Search . pagefind = await import ( pagefindURL ) ;
342
352
const options = {
343
353
ranking : {
344
354
pageLength : 0.1 , // boost longer pages
0 commit comments