diff --git a/README.md b/README.md index 434c12d..781d8fa 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ - Supports multiple instances of the component on a page - Supports pre-filled search query - Supports [Astro view transitions](https://docs.astro.build/en/guides/view-transitions) +- Allows [passing index config](packages/example/astro.config.ts) to pagefind ## Usage diff --git a/packages/astro-pagefind/src/pagefind.ts b/packages/astro-pagefind/src/pagefind.ts index 6d7c87d..16768b9 100644 --- a/packages/astro-pagefind/src/pagefind.ts +++ b/packages/astro-pagefind/src/pagefind.ts @@ -1,10 +1,20 @@ import type { AstroIntegration } from "astro"; import { fileURLToPath } from "node:url"; import path from "node:path"; -import { createIndex } from "pagefind"; +import { createIndex, type PagefindServiceConfig } from "pagefind"; import sirv from "sirv"; -export default function pagefind(): AstroIntegration { +/** + * Pagefind Astro integration options. + */ +export interface PagefindOptions { + /** + * `PagefindServiceConfig` passed to pagefind's `createIndex` + */ + indexConfig?: PagefindServiceConfig; +} + +export default function pagefind({ indexConfig }: PagefindOptions = {}): AstroIntegration { let outDir: string; return { name: "pagefind", @@ -55,7 +65,7 @@ export default function pagefind(): AstroIntegration { return; } - const { index, errors: createErrors } = await createIndex({}); + const { index, errors: createErrors } = await createIndex(indexConfig); if (!index) { logger.error("Pagefind failed to create index"); createErrors.forEach((e) => logger.error(e)); diff --git a/packages/example/astro.config.ts b/packages/example/astro.config.ts index 12d2d76..abdfe23 100644 --- a/packages/example/astro.config.ts +++ b/packages/example/astro.config.ts @@ -6,5 +6,12 @@ export default defineConfig({ build: { format: "file", }, - integrations: [pagefind()], + integrations: [ + pagefind({ + // Example of specifying Pagefind config: + indexConfig: { + keepIndexUrl: true, + }, + }), + ], });