From 3d3d32cc3528804fa8f5dc8ac90e7811cd4a2512 Mon Sep 17 00:00:00 2001 From: Mike Fiedler Date: Fri, 31 Jan 2025 14:40:04 +0100 Subject: [PATCH] feat: add pagefind search Instead of using sphinx's built-in search which has some challenges in its implementation, as well as the integration with the customized builder and theme, use a different approach. Pagefind will generate fragments that can be loaded client-side efficiently. Refs: https://pagefind.app/ Refs: https://pypi.org/project/pagefind/ Signed-off-by: Mike Fiedler --- Makefile | 1 + .../pep_processor/transforms/pep_title.py | 6 +++++- pep_sphinx_extensions/pep_theme/templates/page.html | 10 +++++++++- requirements.txt | 2 ++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 988eba44892..dee55cf129d 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,7 @@ ALLSPHINXOPTS = --builder $(BUILDER) \ .PHONY: html html: venv $(SPHINXBUILD) $(ALLSPHINXOPTS) + $(VENVDIR)/bin/python3 -m pagefind --site $(BUILDDIR) --verbose ## htmlview to open the index page built by the html target in your browser .PHONY: htmlview diff --git a/pep_sphinx_extensions/pep_processor/transforms/pep_title.py b/pep_sphinx_extensions/pep_processor/transforms/pep_title.py index de3ce4466a1..c5f0fae8318 100644 --- a/pep_sphinx_extensions/pep_processor/transforms/pep_title.py +++ b/pep_sphinx_extensions/pep_processor/transforms/pep_title.py @@ -44,7 +44,11 @@ def apply(self) -> None: # Generate the title section node and its properties title_nodes = _line_to_nodes(pep_title_string) - pep_title_node = nodes.section("", nodes.title("", "", *title_nodes, classes=["page-title"]), names=["pep-content"]) + # TODO: Why doesn't the new attribute show up in the HTML output? + # This is needed to change the way the index entry titles are generated, + # but is currently getting ignored/removed somewhere in the stack. + pep_title_attributes = {"classes": ["page-title"], "data-pagefind-meta": "title"} + pep_title_node = nodes.section("", nodes.title("", "", *title_nodes, **pep_title_attributes), names=["pep-content"]) # Insert the title node as the root element, move children down document_children = self.document.children diff --git a/pep_sphinx_extensions/pep_theme/templates/page.html b/pep_sphinx_extensions/pep_theme/templates/page.html index 0b821712974..c5c5dd325af 100644 --- a/pep_sphinx_extensions/pep_theme/templates/page.html +++ b/pep_sphinx_extensions/pep_theme/templates/page.html @@ -12,6 +12,7 @@ + @@ -46,11 +47,12 @@

Python Enhancement Proposals

Toggle light / dark / auto colour theme -
+
{{ body }}
{%- if not pagename.startswith(("404", "numerical")) %}