Skip to content

Commit

Permalink
Merge pull request #106 from shishkin/pagefind-config
Browse files Browse the repository at this point in the history
Pagefind config
  • Loading branch information
shishkin authored Jan 24, 2025
2 parents c2f09ab + 419cf34 commit 8186a8a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
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,
},
}),
],
});

0 comments on commit 8186a8a

Please sign in to comment.