pagefind integration and search bar

This commit is contained in:
Xanazf 2024-10-04 20:14:32 +03:00
parent a787497feb
commit cd1226e333
19 changed files with 565 additions and 240 deletions

28
pagefind.ts Normal file
View file

@ -0,0 +1,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());
});
},
},
};
}