From b065dbfed7d9c12e917339a4011f6af7767bb80b Mon Sep 17 00:00:00 2001 From: Ricardo Date: Wed, 18 Feb 2026 17:08:05 +0100 Subject: [PATCH] fix: use full date-prefixed filenames for OG images MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Nunjucks race condition in Eleventy 3.x affects page.url too — its value changes between {% set %} and {{ }} within the same template render during parallel builds. Instead of trying to derive slugs from page data, name OG images with the full filename (including date prefix) to match URL path segments exactly. --- eleventy.config.js | 6 +++--- lib/og.js | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/eleventy.config.js b/eleventy.config.js index 5d8c3af..c599a0d 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -363,11 +363,11 @@ export default function (eleventyConfig) { }); // Derive OG slug from page.url (reliable) instead of page.fileSlug - // (which suffers from Nunjucks race conditions in Eleventy 3.x parallel rendering) + // (which suffers from Nunjucks race conditions in Eleventy 3.x parallel rendering). + // OG images are named with the full date prefix to match URL segments exactly. eleventyConfig.addFilter("ogSlug", (url) => { if (!url) return ""; - const last = url.replace(/\/$/, "").split("/").pop(); - return last.replace(/^\d{4}-\d{2}-\d{2}-/, ""); + return url.replace(/\/$/, "").split("/").pop(); }); // Check if a generated OG image exists for this slug diff --git a/lib/og.js b/lib/og.js index dd672ae..b13df90 100644 --- a/lib/og.js +++ b/lib/og.js @@ -106,11 +106,12 @@ function formatDate(dateStr) { } /** - * Strip YYYY-MM-DD- date prefix from filename to match Eleventy's page.fileSlug. - * Eleventy v3 parses dates from filenames and removes the prefix from fileSlug. + * Use the full filename (with date prefix) as the OG image slug. + * This matches the URL path segment directly, avoiding Eleventy's page.fileSlug + * race condition in Nunjucks parallel rendering. */ -function toEleventySlug(filename) { - return filename.replace(/^\d{4}-\d{2}-\d{2}-/, ""); +function toOgSlug(filename) { + return filename; } function truncateTitle(title, max = 120) { @@ -307,7 +308,7 @@ export async function generateOgImages(contentDir, cacheDir, siteName) { continue; } - const slug = toEleventySlug(basename(filePath, ".md")); + const slug = toOgSlug(basename(filePath, ".md")); const title = fm.title || fm.name || extractBodyText(raw); const date = fm.published || fm.date || ""; const postType = detectPostType(filePath);