Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 13 additions & 3 deletions packages/astro-pagefind/src/pagefind.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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));
Expand Down
9 changes: 8 additions & 1 deletion packages/example/astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,12 @@ export default defineConfig({
build: {
format: "file",
},
integrations: [pagefind()],
integrations: [
pagefind({
// Example of specifying Pagefind config:
indexConfig: {
keepIndexUrl: true,
},
}),
],
});
Loading