From de09db61711ea5c1659edd873112cfbdfea8951d Mon Sep 17 00:00:00 2001 From: Ricardo Date: Wed, 18 Feb 2026 08:59:25 +0100 Subject: [PATCH] fix: skip hidden images in extractFirstImage, fix OG subprocess NODE_OPTIONS Two fixes: - extractFirstImage filter now skips tags with the hidden attribute, preventing the author avatar microformat from being used as og:image - Clear NODE_OPTIONS in the OG subprocess env and pass --max-old-space-size as a direct CLI flag to avoid conflict with parent process settings --- eleventy.config.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/eleventy.config.js b/eleventy.config.js index 55335a9..6a58139 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -299,13 +299,14 @@ export default function (eleventyConfig) { // Extract first image from content for OpenGraph fallback eleventyConfig.addFilter("extractFirstImage", (content) => { if (!content) return null; - // Match tags and extract src attribute - const imgMatch = content.match(/]+src=["']([^"']+)["']/i); - if (imgMatch && imgMatch[1]) { - let src = imgMatch[1]; - // Skip data URIs and external placeholder images - if (src.startsWith('data:')) return null; - // Return the src (will be made absolute in template) + // Match all tags, skip hidden ones and data URIs + const imgRegex = /]+src=["']([^"']+)["'][^>]*>/gi; + let match; + while ((match = imgRegex.exec(content)) !== null) { + const fullTag = match[0]; + const src = match[1]; + if (src.startsWith("data:")) continue; + if (/\bhidden\b/.test(fullTag)) continue; return src; } return null; @@ -531,13 +532,14 @@ export default function (eleventyConfig) { const siteName = process.env.SITE_NAME || "My IndieWeb Blog"; try { execFileSync(process.execPath, [ + "--max-old-space-size=768", resolve(__dirname, "lib", "og-cli.js"), contentDir, cacheDir, siteName, ], { stdio: "inherit", - env: { ...process.env, NODE_OPTIONS: "--max-old-space-size=768" }, + env: { ...process.env, NODE_OPTIONS: "" }, }); } catch (err) { console.error("[og] Image generation failed:", err.message);