From 4fb7e2e92e1926bb193098c09bd75e9fa61d76a5 Mon Sep 17 00:00:00 2001 From: Ricardo Date: Mon, 2 Mar 2026 16:04:31 +0100 Subject: [PATCH] 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 --- eleventy.config.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/eleventy.config.js b/eleventy.config.js index 5b5eac3..059c624 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -11,7 +11,7 @@ import registerUnfurlShortcode, { getCachedCard, prefetchUrl } from "./lib/unfur import matter from "gray-matter"; import { createHash } from "crypto"; 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 { fileURLToPath } from "url"; @@ -932,6 +932,25 @@ export default function (eleventyConfig) { stdio: "inherit", 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) { console.error("[og] Image generation failed:", err.message); }