fix: use one-shot flag for pagefind instead of incremental guard
The --incremental CLI flag sets incremental=true in eleventy.after even for the watcher's first full build, so pagefind was never running when the initial build was OOM-killed. Replace the incremental guard with a pagefindDone boolean that runs pagefind exactly once per process lifetime — whichever build completes first (initial or watcher) gets indexed.
This commit is contained in:
+21
-15
@@ -663,24 +663,30 @@ export default function (eleventyConfig) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Post-build hook: pagefind indexing + WebSub notification
|
// Post-build hook: pagefind indexing + WebSub notification
|
||||||
// Runs after every full build (initial + watcher's first build), skips incremental rebuilds
|
// Pagefind runs once on the first build (initial or watcher's first full build), then never again.
|
||||||
|
// WebSub runs on every non-incremental build.
|
||||||
|
// Note: --incremental CLI flag sets incremental=true even for the watcher's first full build,
|
||||||
|
// so we cannot use the incremental flag to guard pagefind. Use a one-shot flag instead.
|
||||||
|
let pagefindDone = false;
|
||||||
eleventyConfig.on("eleventy.after", async ({ dir, directories, runMode, incremental }) => {
|
eleventyConfig.on("eleventy.after", async ({ dir, directories, runMode, incremental }) => {
|
||||||
if (incremental) return;
|
// Pagefind indexing — run exactly once per process lifetime
|
||||||
|
if (!pagefindDone) {
|
||||||
// Pagefind indexing — use directories.output (reflects --output CLI flag)
|
pagefindDone = true;
|
||||||
const outputDir = directories?.output || dir.output;
|
const outputDir = directories?.output || dir.output;
|
||||||
try {
|
try {
|
||||||
console.log(`[pagefind] Indexing ${outputDir} (${runMode})...`);
|
console.log(`[pagefind] Indexing ${outputDir} (${runMode})...`);
|
||||||
execFileSync("npx", ["pagefind", "--site", outputDir, "--output-subdir", "pagefind", "--glob", "**/*.html"], {
|
execFileSync("npx", ["pagefind", "--site", outputDir, "--output-subdir", "pagefind", "--glob", "**/*.html"], {
|
||||||
stdio: "inherit",
|
stdio: "inherit",
|
||||||
timeout: 120000,
|
timeout: 120000,
|
||||||
});
|
});
|
||||||
console.log("[pagefind] Indexing complete");
|
console.log("[pagefind] Indexing complete");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("[pagefind] Indexing failed:", err.message);
|
console.error("[pagefind] Indexing failed:", err.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebSub hub notification — notify subscribers of feed updates
|
// WebSub hub notification — skip on incremental rebuilds
|
||||||
|
if (incremental) return;
|
||||||
const hubUrl = "https://websubhub.com/hub";
|
const hubUrl = "https://websubhub.com/hub";
|
||||||
const feedUrls = [
|
const feedUrls = [
|
||||||
`${siteUrl}/`,
|
`${siteUrl}/`,
|
||||||
|
|||||||
Reference in New Issue
Block a user