fix: run OG image generation in subprocess to prevent OOM kill

The OG generation in the eleventy.before hook consumed too much memory
alongside Eleventy's data cascade, causing the Eleventy process to be
OOM-killed on Cloudron. Fix by running OG generation in a separate
child process with its own 768MB heap limit. Also write the manifest
incrementally (every 10 images) to preserve progress if interrupted.
This commit is contained in:
Ricardo
2026-02-18 08:49:11 +01:00
parent afc394525b
commit 86cbc1ee5d
3 changed files with 35 additions and 3 deletions

View File

@@ -10,7 +10,6 @@ import { minify } from "html-minifier-terser";
import { createHash } from "crypto";
import { execFileSync } from "child_process";
import { readFileSync, existsSync } from "fs";
import { generateOgImages } from "./lib/og.js";
import { resolve, dirname } from "path";
import { fileURLToPath } from "url";
@@ -526,12 +525,20 @@ export default function (eleventyConfig) {
});
// Generate OpenGraph images for posts without photos
eleventyConfig.on("eleventy.before", async () => {
eleventyConfig.on("eleventy.before", () => {
const contentDir = resolve(__dirname, "content");
const cacheDir = resolve(__dirname, ".cache");
const siteName = process.env.SITE_NAME || "My IndieWeb Blog";
try {
await generateOgImages(contentDir, cacheDir, siteName);
execFileSync(process.execPath, [
resolve(__dirname, "lib", "og-cli.js"),
contentDir,
cacheDir,
siteName,
], {
stdio: "inherit",
env: { ...process.env, NODE_OPTIONS: "--max-old-space-size=768" },
});
} catch (err) {
console.error("[og] Image generation failed:", err.message);
}