Skip to content

Commit ce18063

Browse files
authored
feat(Buscador): agregar flexsearch #169
2 parents 224fddc + 249e206 commit ce18063

File tree

7 files changed

+990
-697
lines changed

7 files changed

+990
-697
lines changed

.github/workflows/build_docs.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ on:
1919
- themes/**
2020
- plugins/**
2121
- images/**
22-
2322
jobs:
2423
build:
2524

README.rst

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1-
Este es el repositorio de los contenidos de la Wiki de Python Argentina
2-
3-
| http://wiki.python.org.ar/
4-
5-
6-
Podés editar los contenidos (incluso agregar páginas) y proponer un pull request, que se
7-
sincronizará automáticamente con la wiki una vez que sea mezclado.
8-
9-
Pueden ver como colaborar en la página de `Cómo colaborar
10-
<https://wiki.python.org.ar/colaborandoenelwiki>`__
11-
12-
Cómo buildear las páginas
13-
=========================
14-
15-
El contenido de la wiki está escrito en `Markdown <https://es.wikipedia.org/wiki/Markdown>`__ o `reStructeredText <https://es.wikipedia.org/wiki/ReStructuredText>`__ y se
16-
transforma a `HTML` con `nikola <https://getnikola.com/>`__, un generador de sitios estáticos escrito en python.
17-
18-
.. code-block:: console
19-
20-
pip install -U pip
21-
pip install -r requirements.txt
22-
23-
nikola build
24-
nikola serve
1+
Este es el repositorio de los contenidos de la Wiki de Python Argentina
2+
3+
| http://wiki.python.org.ar/
4+
5+
Podés editar los contenidos (incluso agregar páginas) y proponer un pull request, que se
6+
sincronizará automáticamente con la wiki una vez que sea mezclado.
7+
8+
Antes de clonar el repo, asegurate de tener instalado [Git LFS](https://git-lfs.github.com/)
9+
10+
Pueden ver como colaborar en la página de `Cómo colaborar
11+
<https://github.com/PyAr/wiki/blob/nikola/pages/colaborandoenelwiki.rst>`__
12+
13+
Cómo buildear las páginas
14+
=========================
15+
16+
.. code-block:: console
17+
18+
python -m venv .venv
19+
.\.venv\Scripts\Activate.ps1 # en PowerShell
20+
. .venv\bin\activate # en Bash
21+
22+
.. code-block:: console
23+
24+
.venv> python -m pip install -U pip
25+
.venv> python -m pip install -r requirements.txt
26+
27+
.. code-block:: console
28+
29+
.venv> nikola build
30+
.venv> nikola serve
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[Core]
2+
Name = flexsearch_plugin
3+
Module = flexsearch_plugin
4+
5+
[Documentation]
6+
Author = Diego Carrasco G.
7+
Version = 0.1
8+
Website = https://plugins.getnikola.com/#flexsearch_plugin
9+
Description = Adds FlexSearch full-text search capabilities to Nikola static sites.
10+
11+
[Nikola]
12+
MinVersion = 8.0.0 # I haven't tested it with older versions
13+
MaxVersion = 8.3.1
14+
PluginCategory = LateTask
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# MIT License
2+
#
3+
# Copyright (c) [2024] [Diego Carrasco G.]
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
import os
24+
import json
25+
from nikola.plugin_categories import LateTask
26+
from nikola import utils
27+
28+
29+
class FlexSearchPlugin(LateTask):
30+
'''iterea sobre todos los post
31+
saca el titulo y el contenido del tituo y el url
32+
'''
33+
name = "flexsearch_plugin"
34+
35+
def set_site(self, site):
36+
super(FlexSearchPlugin, self).set_site(site)
37+
self.site = site
38+
site.register_path_handler('search_index', self.search_index_path)
39+
40+
def gen_tasks(self):
41+
"""Generate the search index after all posts are processed."""
42+
self.site.scan_posts()
43+
yield self.group_task()
44+
45+
output_path = self.site.config['OUTPUT_FOLDER']
46+
index_file_path = os.path.join(output_path, 'assets', 'search_index.json')
47+
48+
def build_index():
49+
"""Build the entire search index from scratch."""
50+
index = {}
51+
for post in self.site.timeline:
52+
# Sasha: Modifico esta linea para que considere todas las entradas bajo /pages
53+
if not post.is_draft:
54+
index[post.meta('slug')] = {
55+
'title': post.title(),
56+
'content': post.text(strip_html=True),
57+
'url': post.permalink(absolute=False)
58+
}
59+
with open(index_file_path, 'w', encoding='utf-8') as f:
60+
json.dump(index, f, ensure_ascii=False)
61+
62+
task = {
63+
'basename': self.name,
64+
'name': 'all_posts',
65+
'actions': [build_index],
66+
'targets': [index_file_path],
67+
'uptodate': [utils.config_changed({1: self.site.GLOBAL_CONTEXT})],
68+
'clean': True,
69+
}
70+
yield task
71+
72+
def search_index_path(self, name, lang):
73+
return [os.path.join(self.site.config['BASE_URL'], 'search_index.json'), None]

0 commit comments

Comments
 (0)