Skip to content

3di | Implement Pagefind for enhanced search capability (backport #7318) - #7475

Merged
ahcorde merged 1 commit into
lyricalfrom
mergify/bp/lyrical/pr-7318
Nov 12, 2026
Merged

ahcorde merged 1 commit into
lyricalfrom
mergify/bp/lyrical/pr-7318

Conversation

@mergify

@mergify mergify Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Description

This PR replaces Sphinx's built-in search with Pagefind, a static, client-side search index, using the Pagefind Component UI (pinned to 1.5.2). Search results can be filtered by the .. meta:: fields added in the Enhance metadata work (#6981).

Search UI

  • The sidebar search box opens a lightbox (also ⌘K / Ctrl+K). Results appear as you type. Pressing Enter opens search.html with the term and the selected filters, including from search.html itself.
  • search.html is a full-page search with a filter sidebar. ?q= and filter parameters in the URL are applied on load. Clear resets the term, the filters and the URL.
  • Result cards show the page's navigation breadcrumb (In: Framework › Nodes › …). Optionally they can also show its metadata values.
  • The Distribution filter defaults to the distro the page was built for.

Filters

  • Filters come from .. meta:: fields listed under search_result_meta in pagefind.yml, in that order and with those labels. Only those fields become filters; other meta fields stay plain SEO <meta> tags.
  • always_show_filters keeps chosen filter groups visible, with an empty placeholder when no indexed page has that field.
  • Every indexed option stays visible, and per-option page counts are hidden. Options ticked within one group match any of them (OR). Different groups, and the search term, must all match (AND).

Indexing

  • Only page bodies are indexed (data-pagefind-body in source/_templates/layout.html). Redirect stubs from .. redirect-from:: are excluded.
  • Heading permalink anchors, "Contents" labels and in-page .. showmeta:: summaries are left out of the index.
  • make multiversion produces one index at the site root covering every distro. The Distribution filter separates them.

Build

  • make html and make multiversion build as before, then run make pagefind (npx pagefind@1.5.2 --site build/html). This needs Node.js 18+.
  • make serve (sphinx-autobuild) keeps Sphinx's built-in search (-D pagefind_enabled=0), so live preview doesn't re-index on every save.
  • Search doesn't work from file://. Preview with python3 -m http.server --directory build/html.
  • CI installs Node 24 before building.

Dependencies

  • Filters need pages to have .. meta:: fields (3di | Enhance metadata #6981). Pages without them are still searchable, just not filterable.
  • Deployment: the production doc job needs Node.js available, so that make multiversion can run the Pagefind step.

Testing

  1. make html
  2. python3 -m http.server --directory build/html and open http://127.0.0.1:8000.
  3. Search from the sidebar lightbox, press Enter, then check filters, breadcrumbs and Clear on search.html.
  4. Unit tests: python -m pytest test/test_pagefind_config.py test/test_pagefind_meta.py

Changes

  • Add pagefind.yml: Pagefind CLI options plus search UI settings (filters and their labels, always-shown filters, breadcrumbs, result metadata, excerpt length).
  • Add plugins/pagefind_config.py: loads pagefind.yml into Sphinx settings; adds the pagefind_enabled switch.
  • Add plugins/pagefind_meta.py: emits filter and SEO <meta> tags and breadcrumb metadata, and passes the search settings to the page templates.
  • Add source/_static/pagefind-search.js (search UI behaviour) and source/_static/pagefind-docsearch.css.
  • Add templates layout.html, search.html, searchbox.html, pagefind-search.html and pagefind-searchbox.html.
  • Add tests test/test_pagefind_config.py and test/test_pagefind_meta.py.
  • Update Makefile (pagefind target; html and multiversion run it; serve keeps Sphinx search), conf.py (register the extensions), requirements.txt (PyYAML), .github/workflows/test.yml (Node setup) and README.md.
  • conf.py: PRODUCT macro set to ROS and defined for multiversion builds.

Did you use Generative AI?

Yes - Cursor IDE using models Composer 2.5, Grok 4.7, and Anthropic Opus 5.

Additional Information

Issue: #6991 | #6981


This is an automatic backport of pull request #7318 done by Mergify.

Signed-off-by: Alejandro Hernandez Cordero <ahcorde@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alejandro Hernandez Cordero <ahcorde@gmail.com>
(cherry picked from commit cca51e0)
@github-actions

Copy link
Copy Markdown

HTML artifacts: https://github.com/ros2/ros2_documentation/actions/runs/43138364993/artifacts/13907989768.

To view the resulting site:

  1. Click on the above link to download the artifacts archive
  2. Extract it
  3. Open html-artifacts-7475/index.html in your favorite browser

@ahcorde
ahcorde merged commit 93810d9 into lyrical Nov 12, 2026
6 checks passed
@ahcorde
ahcorde deleted the mergify/bp/lyrical/pr-7318 branch November 12, 2026 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants