11
22async function loadIndex ( ) {
3- const response = await fetch ( `/${ getLang ( ) } /search_index.json` ) ;
3+ const response = await fetch ( `${ getBaseUrl ( ) } /${ getLang ( ) } /search_index.json` ) ;
44 return response . json ( ) ;
55}
66
@@ -14,6 +14,12 @@ function getLang() {
1414 return pathParts . length > 0 ? pathParts [ 0 ] : '' ;
1515}
1616
17+ function getBaseUrl ( ) {
18+ // Detect if we're on GitHub Pages (production) or localhost (dev)
19+ const isLocal = window . location . hostname === 'localhost' || window . location . hostname === '127.0.0.1' ;
20+ return isLocal ? '' : '/Field-Guide' ;
21+ }
22+
1723function boldQuery ( text , query ) {
1824 if ( ! query ) return text ;
1925 const regex = new RegExp ( `(${ query } )` , 'gi' ) ;
@@ -56,7 +62,7 @@ document.getElementById('search-box').addEventListener('keydown', function (e) {
5662 const query = encodeURIComponent ( this . value . trim ( ) ) ;
5763 if ( ! query ) return ;
5864
59- const target = `/${ getLang ( ) } /search.html?q=${ query } ` ;
65+ const target = `${ getBaseUrl ( ) } /${ getLang ( ) } /search.html?q=${ query } ` ;
6066
6167 window . location . href = target ;
6268 }
@@ -66,6 +72,6 @@ function handleSearch(e) {
6672 e . preventDefault ( ) ; // Prevent page reload
6773 const query = document . getElementById ( 'search-box' ) . value . trim ( ) ;
6874 if ( ! query ) return ;
69- const target = `/${ getLang ( ) } /search.html?q=${ query } ` ;
75+ const target = `${ getBaseUrl ( ) } /${ getLang ( ) } /search.html?q=${ query } ` ;
7076 window . location . href = target ;
7177}
0 commit comments