mirror of
https://github.com/svemagie/blog-eleventy-indiekit.git
synced 2026-04-02 16:44:56 +02:00
fix: skip hidden images in extractFirstImage, fix OG subprocess NODE_OPTIONS
Two fixes: - extractFirstImage filter now skips <img> 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
This commit is contained in:
@@ -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 <img> tags and extract src attribute
|
||||
const imgMatch = content.match(/<img[^>]+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 <img> tags, skip hidden ones and data URIs
|
||||
const imgRegex = /<img[^>]+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);
|
||||
|
||||
Reference in New Issue
Block a user