11// Basado en https://plugins.getnikola.com/#flexsearch_plugin
22
3+
34document . addEventListener ( 'DOMContentLoaded' , function ( ) {
4- var searchIndex = new FlexSearch . Index ( ) ; // Initialize FlexSearch
5- var index = { } ; // This will store the index data globally within this script block
5+
6+ const wiki_host_for_dev_or_prod = [ '127.0.0.1' , 'localhost' , '0.0.0.0' , 'wiki.python.org.ar' ] ;
7+
8+ var searchIndex = new FlexSearch . Index ( {
9+ tokenize : "full" ,
10+ async : true ,
11+ } ) ; // Initialize FlexSearch
12+ var index = { } ;
613
714 // Fetch the generated JSON file
8- const basePath = "" //document.location.hostname == "localhost" ? "": "/wiki" //Parche para probar en las GHP de mi fork ak.saxa.xyz/wiki
9- var indexPath = document . location . origin + basePath + "/search_index.json"
15+ function get_basePath ( ) {
16+ // evalua si el url.host NO es igual a wiki.python.org.ar para setear el basepath de los links
17+ if ( wiki_host_for_dev_or_prod . includes ( window . location . hostname ) ) {
18+ return basePath = window . location . host
19+ } else {
20+ // asumimos que el wiki esta alojado bajo /wiki por la relación de las github_pages
21+ return basePath = window . location . host + "/wiki" ;
22+ }
23+ } ;
24+
25+ get_basePath ( )
26+ var indexPath = `//${ basePath } /assets/search_index.json` ;
27+
1028 fetch ( indexPath )
1129 . then ( response => response . json ( ) )
1230 . then ( data => {
@@ -42,7 +60,7 @@ document.addEventListener('DOMContentLoaded', function() {
4260 results . forEach ( function ( result ) {
4361 var li = document . createElement ( 'li' ) ; // Create a LI element for each result
4462 var link = document . createElement ( 'a' ) ;
45- link . href = basePath + index [ result ] . url ;
63+ link . href = `// ${ basePath } ${ index [ result ] . url } ` ;
4664 link . textContent = index [ result ] . title ;
4765 li . appendChild ( link ) ;
4866 ul . appendChild ( li ) ; // Append the LI to the UL
@@ -60,13 +78,6 @@ document.addEventListener('DOMContentLoaded', function() {
6078 // Event listener for each change in the input field
6179 input . addEventListener ( 'input' , performSearch ) ;
6280
63- // Function to close the search overlay
64- function closeSearch ( ) {
65- document . getElementById ( 'search_overlay' ) . style . display = 'none' ;
66- document . getElementById ( 'search_input_base' ) . disabled = false ;
67- document . getElementById ( 'search_input' ) . value === ""
68- }
69-
7081 document . addEventListener ( 'keydown' , function ( event ) {
7182 if ( event . key === 'Escape' ) {
7283 var searchOverlay = document . getElementById ( 'search_overlay' ) ;
@@ -77,4 +88,11 @@ document.addEventListener('DOMContentLoaded', function() {
7788 } ) ;
7889} ) ;
7990
91+ // Function to close the search overlay
92+ function closeSearch ( ) {
93+ document . getElementById ( 'search_overlay' ) . style . display = 'none' ;
94+ document . getElementById ( 'search_input_base' ) . disabled = false ;
95+ document . getElementById ( 'search_input' ) . value === ""
96+ } ;
97+
8098
0 commit comments