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);