-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpagefind.ts
More file actions
28 lines (27 loc) · 809 Bytes
/
Copy pathpagefind.ts
File metadata and controls
28 lines (27 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import type { AstroIntegration } from "astro";
import { fileURLToPath } from "node:url";
import { spawn } from "node:child_process";
import { dirname, relative } from "node:path";
export default function pagefind(): AstroIntegration {
return {
name: "pagefind",
hooks: {
"astro:build:done": ({ dir }) => {
const targetDir = fileURLToPath(dir);
const cwd = dirname(fileURLToPath(import.meta.url));
const relativeDir = relative(cwd, targetDir);
return new Promise<void>(resolve => {
spawn(
"yarn dlx",
["-q", "pagefind", "--site", relativeDir],
{
stdio: "inherit",
shell: true,
cwd,
}
).on("close", () => resolve());
});
},
},
};
}