Exclude code from the Pagefind search index#306
Open
Zneeky wants to merge 2 commits into
Open
Conversation
Register the rehype-pagefind-ignore plugin from igniteui-astro-components in the rehype pipeline. It marks code blocks and single character inline code with data-pagefind-ignore so Pagefind stops indexing their one letter tokens, which were producing weak, irrelevant prefix matches (for example a search for "twitter" matching the "t" in "keyof T" across unrelated API pages).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Waits: IgniteUI/igniteui-astro-components#74
Summary
Registers the
rehype-pagefind-ignoreplugin (shipped byigniteui-astro-components) in the rehype pipeline so Pagefind stops indexing
code. This is the build side half of the search improvements; the search UI
changes live in the igniteui-astro-components package.
Why
Pagefind indexes all text inside
<main>, including highlighted code. Code isfull of one letter tokens such as the generic
Tor the escape\t. When aquery has no strong match, Pagefind falls back to weak prefix matching and
latches onto those single characters, so a search for "twitter" returned many
unrelated API pages, with code fragments as the excerpts.
What changed
Two lines in
src/integration.ts:rehypePagefindIgnorefromigniteui-astro-components/plugins/rehype-pagefind-ignorerehypePluginsarray increateDocsSiteThe plugin marks fenced code blocks and single character inline code with
data-pagefind-ignore, so matches and excerpts come from real prose. Multicharacter inline code such as
dataSourcestays indexed and searchable.