@@ -21,10 +21,12 @@ popped = 'state' in window.history;
2121initialURL = location . href ;
2222
2323const 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' ) ;
2830} ) ( ) ;
2931
3032$ ( document ) . ready ( function ( ) {
@@ -338,7 +340,15 @@ var Search = {
338340 return ;
339341 }
340342 ( 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 ) ;
342352 const options = {
343353 ranking : {
344354 pageLength : 0.1 , // boost longer pages
0 commit comments