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: add pagefind search #4247

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@

# 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"])

Check warning on line 51 in pep_sphinx_extensions/pep_processor/transforms/pep_title.py

View check run for this annotation

Codecov / codecov/patch

pep_sphinx_extensions/pep_processor/transforms/pep_title.py#L50-L51

Added lines #L50 - L51 were not covered by tests

# Insert the title node as the root element, move children down
document_children = self.document.children
Expand Down
10 changes: 9 additions & 1 deletion pep_sphinx_extensions/pep_theme/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<link rel="stylesheet" href="{{ pathto('_static/mq.css', resource=True) }}" type="text/css">
<link rel="stylesheet" href="{{ pathto('_static/pygments.css', resource=True) }}" type="text/css" media="(prefers-color-scheme: light)" id="pyg-light">
<link rel="stylesheet" href="{{ pathto('_static/pygments_dark.css', resource=True) }}" type="text/css" media="(prefers-color-scheme: dark)" id="pyg-dark">
<link rel="stylesheet" href="/pagefind/pagefind-ui.css" type="text/css">
<link rel="alternate" type="application/rss+xml" title="Latest PEPs" href="https://peps.python.org/peps.rss">
<meta property="og:title" content='{{ title + " | peps.python.org"|safe }}'>
<meta property="og:description" content="{{ description }}">
Expand Down Expand Up @@ -46,11 +47,12 @@ <h1>Python Enhancement Proposals</h1>
<span class="visually-hidden">Toggle light / dark / auto colour theme</span>
</button>
</header>
<article>
<article data-pagefind-body>
{{ body }}
</article>
{%- if not pagename.startswith(("404", "numerical")) %}
<nav id="pep-sidebar">
<div id="search"></div>
<h2>Contents</h2>
{{ toc }}
<br>
Expand All @@ -63,5 +65,11 @@ <h2>Contents</h2>
<script src="{{ pathto('_static/colour_scheme.js', resource=True) }}"></script>
<script src="{{ pathto('_static/wrap_tables.js', resource=True) }}"></script>
<script src="{{ pathto('_static/sticky_banner.js', resource=True) }}"></script>
<script src="/pagefind/pagefind-ui.js"></script>
<script>
window.addEventListener('DOMContentLoaded', (event) => {
new PagefindUI({ element: "#search", showSubResults: true });
});
</script>
</body>
</html>
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Pygments >= 2.9.0
Sphinx >= 5.1.1, != 6.1.0, != 6.1.1, < 8.1.0
docutils >= 0.19.0
sphinx-notfound-page >= 1.0.2
# For search
pagefind[bin] >= 1.3.0

# For tests
pytest
Expand Down