Skip to content

Commit 300fd08

Browse files
author
Roberto Betancur
committed
basepath arreglado y agregada evaluación de la url mediante lista
1 parent 09ca06e commit 300fd08

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

plugins/flexsearch_plugin/flexsearch_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def gen_tasks(self):
4343
yield self.group_task()
4444

4545
output_path = self.site.config['OUTPUT_FOLDER']
46-
index_file_path = os.path.join(output_path, 'search_index.json')
46+
index_file_path = os.path.join(output_path, 'assets', 'search_index.json')
4747

4848
def build_index():
4949
"""Build the entire search index from scratch."""

themes/pyar/assets/js/flexsearch.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
// Basado en https://plugins.getnikola.com/#flexsearch_plugin
22

3+
34
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+
48
var searchIndex = new FlexSearch.Index({
59
tokenize: "full",
610
async: true,
711
}); // Initialize FlexSearch
812
var index = {};
913

1014
// 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+
1328
fetch(indexPath)
1429
.then(response => response.json())
1530
.then(data => {
@@ -45,7 +60,7 @@ document.addEventListener('DOMContentLoaded', function() {
4560
results.forEach(function(result) {
4661
var li = document.createElement('li'); // Create a LI element for each result
4762
var link = document.createElement('a');
48-
link.href = basePath + index[result].url;
63+
link.href = `//${basePath}${index[result].url}`;
4964
link.textContent = index[result].title;
5065
li.appendChild(link);
5166
ul.appendChild(li); // Append the LI to the UL

0 commit comments

Comments
 (0)