|
1 | 1 | // Basado en https://plugins.getnikola.com/#flexsearch_plugin |
2 | 2 |
|
| 3 | + |
3 | 4 | document.addEventListener('DOMContentLoaded', function() { |
| 5 | + |
| 6 | + const wiki_host_for_dev_or_prod = ['127.0.0.1', 'localhost', '0.0.0.0', 'wiki.python.org.ar']; |
| 7 | + |
4 | 8 | var searchIndex = new FlexSearch.Index({ |
5 | 9 | tokenize: "full", |
6 | 10 | async: true, |
7 | 11 | }); // Initialize FlexSearch |
8 | 12 | var index = {}; |
9 | 13 |
|
10 | 14 | // Fetch the generated JSON file |
11 | | - const basePath = "" //document.location.hostname == "localhost" ? "": "/wiki" //Parche para probar en las GHP de mi fork ak.saxa.xyz/wiki |
12 | | - 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 | + |
13 | 28 | fetch(indexPath) |
14 | 29 | .then(response => response.json()) |
15 | 30 | .then(data => { |
@@ -45,7 +60,7 @@ document.addEventListener('DOMContentLoaded', function() { |
45 | 60 | results.forEach(function(result) { |
46 | 61 | var li = document.createElement('li'); // Create a LI element for each result |
47 | 62 | var link = document.createElement('a'); |
48 | | - link.href = basePath + index[result].url; |
| 63 | + link.href = `//${basePath}${index[result].url}`; |
49 | 64 | link.textContent = index[result].title; |
50 | 65 | li.appendChild(link); |
51 | 66 | ul.appendChild(li); // Append the LI to the UL |
|
0 commit comments