File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change 11
22async function loadIndex ( ) {
3- const response = await fetch ( ` ${ getBaseUrl ( ) } /${ getLang ( ) } /search_index.json`) ;
3+ const response = await fetch ( buildUrl ( ` /${ getLang ( ) } /search_index.json`) ) ;
44 return response . json ( ) ;
55}
66
@@ -20,7 +20,12 @@ function isLocal() {
2020}
2121
2222function getBaseUrl ( ) {
23- return isLocal ( ) ? '' : 'Field-Guide' ;
23+ return isLocal ( ) ? '' : '/Field-Guide' ;
24+ }
25+
26+ function buildUrl ( path ) {
27+ const baseUrl = getBaseUrl ( ) ;
28+ return baseUrl ? `${ baseUrl } ${ path } ` : path ;
2429}
2530
2631function boldQuery ( text , query ) {
@@ -65,16 +70,13 @@ document.getElementById('search-box').addEventListener('keydown', function (e) {
6570 const query = encodeURIComponent ( this . value . trim ( ) ) ;
6671 if ( ! query ) return ;
6772
68- const target = `${ getBaseUrl ( ) } /${ getLang ( ) } /search.html?q=${ query } ` ;
69-
70- window . location . href = target ;
73+ window . location . href = buildUrl ( `/${ getLang ( ) } /search.html?q=${ query } ` ) ;
7174 }
7275} ) ;
7376
7477function handleSearch ( e ) {
7578 e . preventDefault ( ) ; // Prevent page reload
7679 const query = document . getElementById ( 'search-box' ) . value . trim ( ) ;
7780 if ( ! query ) return ;
78- const target = `${ getBaseUrl ( ) } /${ getLang ( ) } /search.html?q=${ query } ` ;
79- window . location . href = target ;
81+ window . location . href = buildUrl ( `/${ getLang ( ) } /search.html?q=${ query } ` ) ;
8082}
You can’t perform that action at this time.
0 commit comments