Skip to content

Commit 249e206

Browse files
authored
fix searchbar accuracy #6
2 parents 97022e0 + 300fd08 commit 249e206

File tree

4 files changed

+55
-28
lines changed

4 files changed

+55
-28
lines changed

plugins/flexsearch_plugin/flexsearch_plugin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727

2828

2929
class FlexSearchPlugin(LateTask):
30+
'''iterea sobre todos los post
31+
saca el titulo y el contenido del tituo y el url
32+
'''
3033
name = "flexsearch_plugin"
3134

3235
def set_site(self, site):
@@ -40,7 +43,7 @@ def gen_tasks(self):
4043
yield self.group_task()
4144

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

4548
def build_index():
4649
"""Build the entire search index from scratch."""

themes/pyar/assets/css/custom.css

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ iframe#google {
112112
padding-top:0;
113113
}
114114

115+
#boton_cerrar {
116+
border-style: groove;
117+
border-width: thin;
118+
width: fit-content;
119+
align-self: self-end;
120+
}
115121

116122
/*
117123
* Panels
@@ -593,19 +599,19 @@ small, .small {
593599
align-items: center;
594600
}
595601

596-
#search_content {
597-
display: flex;
598-
flex-direction: column;
599-
justify-content: space-around;
600-
justify-items: center;
601-
overflow: hidden;
602-
background: white;
603-
padding: 20px;
604-
width: 90%;
605-
max-width: 90%; /* Limit the width on larger screens */
606-
max-height: 90%;
607-
border-radius: 5px;
608-
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
602+
#search_content {
603+
display: flex;
604+
flex-direction: column;
605+
justify-content: space-around;
606+
justify-items: center;
607+
overflow: hidden;
608+
background: white;
609+
padding: 20px;
610+
width: 90%;
611+
max-width: 90%; /* Limit the width on larger screens */
612+
max-height: 90%;
613+
border-radius: 5px;
614+
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
609615
}
610616

611617
#search_results {

themes/pyar/assets/js/flexsearch.js

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

3+
34
document.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

themes/pyar/templates/base.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@
102102
return element.getElementsByTagName('img')[0].alt;
103103
}});
104104
</script>
105-
<script src="https://rawcdn.githack.com/nextapps-de/flexsearch/0.7.31/dist/flexsearch.bundle.js"></script>
105+
<script src="https://cdn.jsdelivr.net/gh/nextapps-de/flexsearch@0.8.0/dist/flexsearch.bundle.min.js"></script>
106106
<script src="/assets/js/flexsearch.js"></script>
107107
{{ body_end }}
108108
{{ template_hooks['body_end']() }}
109109
</body>
110-
</html>
110+
</html>

0 commit comments

Comments
 (0)