fix: sync new OG images to output during incremental builds
During watcher/incremental builds, .cache/og is in watchIgnores so Eleventy's passthrough copy doesn't pick up newly generated OG images. After OG generation, manually copy any new .png files from .cache/og/ to _site/og/ so they're immediately available to serve. Confab-Link: http://localhost:8080/sessions/956f4251-b4a9-4bc9-b214-53402ad1fe63
This commit is contained in:
+20
-1
@@ -11,7 +11,7 @@ import registerUnfurlShortcode, { getCachedCard, prefetchUrl } from "./lib/unfur
|
|||||||
import matter from "gray-matter";
|
import matter from "gray-matter";
|
||||||
import { createHash } from "crypto";
|
import { createHash } from "crypto";
|
||||||
import { execFileSync } from "child_process";
|
import { execFileSync } from "child_process";
|
||||||
import { readFileSync, readdirSync, existsSync, mkdirSync, writeFileSync } from "fs";
|
import { readFileSync, readdirSync, existsSync, mkdirSync, writeFileSync, copyFileSync } from "fs";
|
||||||
import { resolve, dirname } from "path";
|
import { resolve, dirname } from "path";
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
@@ -932,6 +932,25 @@ export default function (eleventyConfig) {
|
|||||||
stdio: "inherit",
|
stdio: "inherit",
|
||||||
env: { ...process.env, NODE_OPTIONS: "" },
|
env: { ...process.env, NODE_OPTIONS: "" },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Sync new OG images to output directory.
|
||||||
|
// During incremental builds, .cache/og is in watchIgnores so Eleventy's
|
||||||
|
// passthrough copy won't pick up newly generated images. Copy them manually.
|
||||||
|
const ogCacheDir = resolve(cacheDir, "og");
|
||||||
|
const ogOutputDir = resolve(__dirname, "_site", "og");
|
||||||
|
if (existsSync(ogCacheDir) && existsSync(resolve(__dirname, "_site"))) {
|
||||||
|
mkdirSync(ogOutputDir, { recursive: true });
|
||||||
|
let synced = 0;
|
||||||
|
for (const file of readdirSync(ogCacheDir)) {
|
||||||
|
if (file.endsWith(".png") && !existsSync(resolve(ogOutputDir, file))) {
|
||||||
|
copyFileSync(resolve(ogCacheDir, file), resolve(ogOutputDir, file));
|
||||||
|
synced++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (synced > 0) {
|
||||||
|
console.log(`[og] Synced ${synced} new image(s) to output`);
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("[og] Image generation failed:", err.message);
|
console.error("[og] Image generation failed:", err.message);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user