mirror of
https://github.com/svemagie/blog-eleventy-indiekit.git
synced 2026-05-15 06:58:50 +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:
+10
-8
@@ -299,13 +299,14 @@ export default function (eleventyConfig) {
|
|||||||
// Extract first image from content for OpenGraph fallback
|
// Extract first image from content for OpenGraph fallback
|
||||||
eleventyConfig.addFilter("extractFirstImage", (content) => {
|
eleventyConfig.addFilter("extractFirstImage", (content) => {
|
||||||
if (!content) return null;
|
if (!content) return null;
|
||||||
// Match <img> tags and extract src attribute
|
// Match all <img> tags, skip hidden ones and data URIs
|
||||||
const imgMatch = content.match(/<img[^>]+src=["']([^"']+)["']/i);
|
const imgRegex = /<img[^>]+src=["']([^"']+)["'][^>]*>/gi;
|
||||||
if (imgMatch && imgMatch[1]) {
|
let match;
|
||||||
let src = imgMatch[1];
|
while ((match = imgRegex.exec(content)) !== null) {
|
||||||
// Skip data URIs and external placeholder images
|
const fullTag = match[0];
|
||||||
if (src.startsWith('data:')) return null;
|
const src = match[1];
|
||||||
// Return the src (will be made absolute in template)
|
if (src.startsWith("data:")) continue;
|
||||||
|
if (/\bhidden\b/.test(fullTag)) continue;
|
||||||
return src;
|
return src;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -531,13 +532,14 @@ export default function (eleventyConfig) {
|
|||||||
const siteName = process.env.SITE_NAME || "My IndieWeb Blog";
|
const siteName = process.env.SITE_NAME || "My IndieWeb Blog";
|
||||||
try {
|
try {
|
||||||
execFileSync(process.execPath, [
|
execFileSync(process.execPath, [
|
||||||
|
"--max-old-space-size=768",
|
||||||
resolve(__dirname, "lib", "og-cli.js"),
|
resolve(__dirname, "lib", "og-cli.js"),
|
||||||
contentDir,
|
contentDir,
|
||||||
cacheDir,
|
cacheDir,
|
||||||
siteName,
|
siteName,
|
||||||
], {
|
], {
|
||||||
stdio: "inherit",
|
stdio: "inherit",
|
||||||
env: { ...process.env, NODE_OPTIONS: "--max-old-space-size=768" },
|
env: { ...process.env, NODE_OPTIONS: "" },
|
||||||
});
|
});
|
||||||
} 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