@@ -14,15 +14,20 @@ class SearchEngine {
1414 this . script = document . createElement ( "script" ) ;
1515 this . script . src = `${ this . SQLITE_BASE } /sql-wasm.js` ;
1616 this . script . addEventListener ( "load" , ( ) => this . onLoadSQLjs ( ) ) ;
17+ this . contentRoot = (
18+ document . getElementById ( "documentation_options" )
19+ ? document . getElementById ( "documentation_options" ) . getAttribute ( 'data-url_root' )
20+ : document . documentElement . dataset . content_root
21+ ) ;
1722 document . body . appendChild ( this . script ) ;
1823 this . renderSearchRunning ( ) ;
1924 }
2025
2126 async onLoadSQLjs ( ) {
2227 const sqlPromise = initSqlJs ( {
23- locateFile : file => `${ this . SQLITE_BASE } /${ file } ` ,
28+ locateFile : file => `${ this . SQLITE_BASE } /${ file } ` ,
2429 } ) ;
25- const dataPromise = fetch ( `${ DOCUMENTATION_OPTIONS . URL_ROOT } db.sqlite` ) . then ( res => res . arrayBuffer ( ) ) ;
30+ const dataPromise = fetch ( `${ this . contentRoot } db.sqlite` ) . then ( res => res . arrayBuffer ( ) ) ;
2631 const [ SQL , buf ] = await Promise . all ( [ sqlPromise , dataPromise ] ) ;
2732 this . db = new SQL . Database ( new Uint8Array ( buf ) ) ;
2833 this . isReady = true ;
@@ -42,7 +47,7 @@ class SearchEngine {
4247 query,
4348 documents : { } ,
4449 } ;
45- while ( stmt . step ( ) ) {
50+ while ( stmt . step ( ) ) {
4651 const rslt = stmt . getAsObject ( ) ;
4752 if ( ! result . documents [ rslt . page ] ) {
4853 result . documents [ rslt . page ] = {
@@ -90,7 +95,7 @@ class SearchEngine {
9095 Object . values ( result . documents ) . forEach ( doc => {
9196 const elm = document . createElement ( "li" ) ;
9297 const root = doc . root || doc . sections [ 0 ] ;
93- const url = new URL ( `${ DOCUMENTATION_OPTIONS . URL_ROOT } ${ root . page } ` , location ) ;
98+ const url = new URL ( `${ this . contentRoot } ${ root . page } ` , location ) ;
9499 url . searchParams . set ( "highlight" , result . query . split ( ) [ 0 ] ) ;
95100 elm . innerHTML = `<a href="${ url . href } ">${ root . doc } </a>` ;
96101 searchResults . querySelector ( "ul.search-list" ) . appendChild ( elm ) ;
@@ -119,8 +124,8 @@ const Search = {
119124 }
120125 } ,
121126
122- loadIndex ( ) { } ,
123- setIndex ( ) { } ,
127+ loadIndex ( ) { } ,
128+ setIndex ( ) { } ,
124129}
125130
126131addEventListener ( "DOMContentLoaded" , ( ) => {
0 commit comments