diff --git a/.changeset/hip-emus-punch.md b/.changeset/hip-emus-punch.md new file mode 100644 index 00000000000..48437412ee5 --- /dev/null +++ b/.changeset/hip-emus-punch.md @@ -0,0 +1,5 @@ +--- +'@astrojs/starlight': patch +--- + +Allow passing user options to pagefind.createIndex diff --git a/docs/src/content/docs/reference/configuration.mdx b/docs/src/content/docs/reference/configuration.mdx index 05f980d8878..3d1a53605a2 100644 --- a/docs/src/content/docs/reference/configuration.mdx +++ b/docs/src/content/docs/reference/configuration.mdx @@ -503,6 +503,7 @@ Set `pagefind` to an object to configure the Pagefind search client: - See [“Customize Pagefind's result ranking”](https://pagefind.app/docs/ranking/) in the Pagefind documentation for more details about using the `pagefind.ranking` option to control how search result ranking is calculated - See [“Searching multiple sites”](https://pagefind.app/docs/multisite/) in the Pagefind documentation for more details about using the `pagefind.mergeIndex` option to control how to search across multiple sites +- See [“pagefind.createIndex”](https://pagefind.app/docs/node-api/#pagefindcreateindex) in the Pagefind documentation for more details about using the `pagefind.index` option to customize what content is indexed. #### `PagefindOptions` @@ -529,6 +530,10 @@ interface PagefindOptions { termSimilarity?: number; }; }>; + index?: Pick< + pagefind.PagefindServiceConfig, + 'rootSelector' | 'excludeSelectors' | 'forceLanguage' + >; } ``` diff --git a/packages/starlight/__tests__/basics/pagefind.test.ts b/packages/starlight/__tests__/basics/pagefind.test.ts index 3e4ac3a2e85..572604800c4 100644 --- a/packages/starlight/__tests__/basics/pagefind.test.ts +++ b/packages/starlight/__tests__/basics/pagefind.test.ts @@ -15,7 +15,7 @@ async function runStarlightPagefind(outputDir: URL) { vi.mocked(pagefind.createIndex).mockResolvedValue({ index, errors: [] }); - await starlightPagefind({ dir: outputDir, logger: new TestAstroIntegrationLogger() }); + await starlightPagefind({ dir: outputDir, logger: new TestAstroIntegrationLogger() }, {}); return index; } @@ -61,7 +61,7 @@ test('logs Pagefind errors and closes Pagefind', async () => { errors: [errorMessage], }); - await expect(starlightPagefind({ dir: outputDir, logger })).rejects.toThrow(); + await expect(starlightPagefind({ dir: outputDir, logger }, {})).rejects.toThrow(); expect(logger.error).toHaveBeenCalledWith(`Pagefind error: ${errorMessage}`); diff --git a/packages/starlight/components/Search.astro b/packages/starlight/components/Search.astro index d8c80d82699..0750d558138 100644 --- a/packages/starlight/components/Search.astro +++ b/packages/starlight/components/Search.astro @@ -75,6 +75,7 @@ if (project.trailingSlash === 'never') dataAttributes['data-strip-trailing-slash