2024-10-04 17:14:32 +00:00
|
|
|
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(
|
2024-11-09 09:09:07 +00:00
|
|
|
"yarn",
|
|
|
|
["pagefind", "--site", relativeDir],
|
2024-10-04 17:14:32 +00:00
|
|
|
{
|
|
|
|
stdio: "inherit",
|
|
|
|
shell: true,
|
|
|
|
cwd,
|
|
|
|
}
|
|
|
|
).on("close", () => resolve());
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|