Skip to content

Commit d2f23be

Browse files
committed
fix: ensure title is set correctly
Since `title` variable is already available in the HTML, use that and hide it from view instead of trying to muck with the nodes during transformation. Signed-off-by: Mike Fiedler <[email protected]>
1 parent 6ff3ea9 commit d2f23be

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

pep_sphinx_extensions/pep_processor/transforms/pep_title.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ def apply(self) -> None:
4444

4545
# Generate the title section node and its properties
4646
title_nodes = _line_to_nodes(pep_title_string)
47-
# TODO: Why doesn't the new attribute show up in the HTML output?
48-
# This is needed to change the way the index entry titles are generated,
49-
# but is currently getting ignored/removed somewhere in the stack.
50-
pep_title_attributes = {"classes": ["page-title"], "data-pagefind-meta": "title"}
51-
pep_title_node = nodes.section("", nodes.title("", "", *title_nodes, **pep_title_attributes), names=["pep-content"])
47+
pep_title_node = nodes.section("", nodes.title("", "", *title_nodes, classes=["page-title"]), names=["pep-content"])
5248

5349
# Insert the title node as the root element, move children down
5450
document_children = self.document.children

pep_sphinx_extensions/pep_theme/templates/page.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ <h1>Python Enhancement Proposals</h1>
4848
</button>
4949
</header>
5050
<article data-pagefind-body>
51+
{# Add pagefind meta for the title to improve search result display #}
52+
<div data-pagefind-meta="title:{{ title }}" style="display:none;"></div>
5153
{{ body }}
5254
</article>
5355
{%- if not pagename.startswith(("404", "numerical")) %}
@@ -70,6 +72,7 @@ <h2>Contents</h2>
7072
<script src="/pagefind/pagefind-ui.js"></script>
7173
<script>
7274
window.addEventListener('DOMContentLoaded', (event) => {
75+
// Initialize pagefind for desktop sidebar
7376
new PagefindUI({ element: "#search", showSubResults: true });
7477
});
7578
</script>

0 commit comments

Comments
 (0)