Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Buscador): agregar flexsearch #169

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
1 change: 0 additions & 1 deletion .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ on:
- themes/**
- plugins/**
- images/**

jobs:
build:

Expand Down
54 changes: 30 additions & 24 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
Este es el repositorio de los contenidos de la Wiki de Python Argentina

| http://wiki.python.org.ar/


Podés editar los contenidos (incluso agregar páginas) y proponer un pull request, que se
sincronizará automáticamente con la wiki una vez que sea mezclado.

Pueden ver como colaborar en la página de `Cómo colaborar
<https://wiki.python.org.ar/colaborandoenelwiki>`__

Cómo buildear las páginas
=========================

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
transforma a `HTML` con `nikola <https://getnikola.com/>`__, un generador de sitios estáticos escrito en python.

.. code-block:: console

pip install -U pip
pip install -r requirements.txt

nikola build
nikola serve
Este es el repositorio de los contenidos de la Wiki de Python Argentina

| http://wiki.python.org.ar/

Podés editar los contenidos (incluso agregar páginas) y proponer un pull request, que se
sincronizará automáticamente con la wiki una vez que sea mezclado.

Antes de clonar el repo, asegurate de tener instalado [Git LFS](https://git-lfs.github.com/)

Pueden ver como colaborar en la página de `Cómo colaborar
<https://github.com/PyAr/wiki/blob/nikola/pages/colaborandoenelwiki.rst>`__

Cómo buildear las páginas
=========================

.. code-block:: console

python -m venv .venv
.\.venv\Scripts\Activate.ps1 # en PowerShell
. .venv\bin\activate # en Bash

.. code-block:: console

.venv> python -m pip install -U pip
.venv> python -m pip install -r requirements.txt

.. code-block:: console

.venv> nikola build
.venv> nikola serve
14 changes: 14 additions & 0 deletions plugins/flexsearch_plugin/flexsearch_plugin.plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Core]
Name = flexsearch_plugin
Module = flexsearch_plugin

[Documentation]
Author = Diego Carrasco G.
Version = 0.1
Website = https://plugins.getnikola.com/#flexsearch_plugin
Description = Adds FlexSearch full-text search capabilities to Nikola static sites.

[Nikola]
MinVersion = 8.0.0 # I haven't tested it with older versions
MaxVersion = 8.3.1
PluginCategory = LateTask
70 changes: 70 additions & 0 deletions plugins/flexsearch_plugin/flexsearch_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# MIT License
#
# Copyright (c) [2024] [Diego Carrasco G.]
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import os
import json
from nikola.plugin_categories import LateTask
from nikola import utils


class FlexSearchPlugin(LateTask):
name = "flexsearch_plugin"

def set_site(self, site):
super(FlexSearchPlugin, self).set_site(site)
self.site = site
site.register_path_handler('search_index', self.search_index_path)

def gen_tasks(self):
"""Generate the search index after all posts are processed."""
self.site.scan_posts()
yield self.group_task()

output_path = self.site.config['OUTPUT_FOLDER']
index_file_path = os.path.join(output_path, 'search_index.json')

def build_index():
"""Build the entire search index from scratch."""
index = {}
for post in self.site.timeline:
# Sasha: Modifico esta linea para que considere todas las entradas bajo /pages
if not post.is_draft:
index[post.meta('slug')] = {
'title': post.title(),
'content': post.text(strip_html=True),
'url': post.permalink(absolute=False)
}
with open(index_file_path, 'w', encoding='utf-8') as f:
json.dump(index, f, ensure_ascii=False)

task = {
'basename': self.name,
'name': 'all_posts',
'actions': [build_index],
'targets': [index_file_path],
'uptodate': [utils.config_changed({1: self.site.GLOBAL_CONTEXT})],
'clean': True,
}
yield task

def search_index_path(self, name, lang):
return [os.path.join(self.site.config['BASE_URL'], 'search_index.json'), None]
Loading
Loading