peps icon indicating copy to clipboard operation
peps copied to clipboard

feat: add pagefind search

Open miketheman opened this issue 9 months ago • 13 comments

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/ Resolves #4083


📚 Documentation preview 📚: https://pep-previews--4247.org.readthedocs.build/

miketheman avatar Jan 31 '25 14:01 miketheman

Definitely needs more styling, and I put it at the top of the sidebar since that made sense to me, but it might be better elsewhere.

Left a TODO - I'm not sure how/when the nodes attributes are getting cleared after PEPTitle.apply() - something else is removing anything non-classes and I wasn't able to figure it out yet.

But give it a whirl!

miketheman avatar Jan 31 '25 14:01 miketheman

The search box looks a little big to me, and it displays "Python Enhancement Proposals" instead of the page titles. But it already looks promising.

nineteendo avatar Jan 31 '25 21:01 nineteendo

@miketheman I'm not familiar with pagefind. I tried the preview site and it works well. Thank you!

willingc avatar Jan 31 '25 23:01 willingc

Thanks gang!

Definitely needs some styling, and mobile theme integration, since that doesn't appear to work on my phone yet.

miketheman avatar Feb 01 '25 08:02 miketheman

Ready for a second round of review. Default styling removed, so that inline/inherited styles work "just well enough".

miketheman avatar Aug 22 '25 20:08 miketheman

The titles are now correct, but it seems the numbering resets every 10 entries.

nineteendo avatar Aug 23 '25 19:08 nineteendo

The titles are now correct, but it seems the numbering resets every 10 entries.

Thanks for checking! Can you share a search that repeats, and maybe a screenshot of the results?

miketheman avatar Aug 23 '25 19:08 miketheman

"Style Guide for C Code":

Screenshot 2025-08-23 at 21 28 16

I also think it doesn't search in the title.

nineteendo avatar Aug 23 '25 19:08 nineteendo

@nineteendo Thanks! That looks to be a Safari-specific behavior, and poking around the HTML it looks like the numbers are accurate, but the first digit is being visually trimmed by not having enough room to display. I'd appreciate it if you can confirm my finding by testing another browser.

I'll keep poking at it for bit longer, to see if there's a "good enough" CSS directive that will fix.

miketheman avatar Aug 24 '25 13:08 miketheman

@nineteendo I've padded the numbers a little, should display correctly in Safari now.

I've also added an exclusion for non-relevant pages, so results should be better.

Searching for "Style Guide for C Code" surfaces a single result now, and unquoted Style Guide for C Code will return based on default search weights and rankings.

miketheman avatar Aug 24 '25 16:08 miketheman

Seems to be fixed (tested with https://browserling.com):

image

Could you also allow searching for titles: "Procedure for Adding New Modules".

nineteendo avatar Aug 24 '25 18:08 nineteendo

Note that still breaks at 100 (on Chrome the "1" is partially cut off):

Screenshot 2025-08-25 at 16 46 37

nineteendo avatar Aug 25 '25 15:08 nineteendo

Note that still breaks at 100 (on Chrome the "1" is partially cut off):

I'll bump it up to 1.8rem in the next commits. Note this this will have the same problem at 1000 results, but I'm also okay, since anyone having to navigate down that far is probably using the wrong search term anyways (and we only have ~708 pages today).

miketheman avatar Sep 08 '25 23:09 miketheman