diff --git a/eleventy.config.js b/eleventy.config.js index fe64b80..1f7753b 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -403,16 +403,16 @@ export default function (eleventyConfig) { if (!outputPath || !outputPath.endsWith(".html")) return content; // Derive correct page URL and OG slug from outputPath (immune to race condition) - // Content pages match: .../type/yyyy/mm/dd/slug/index.html + // Content pages match: .../type/slug/index.html const postMatch = outputPath.match( - /\/([\w-]+)\/(\d{4})\/(\d{2})\/(\d{2})\/([\w-]+)\/index\.html$/ + /\/([\w-]+)\/([\w-]+)\/index\.html$/ ); if (postMatch) { - const [, type, year, month, day, slug] = postMatch; - const pageUrlPath = `/${type}/${year}/${month}/${day}/${slug}/`; + const [, type, slug] = postMatch; + const pageUrlPath = `/${type}/${slug}/`; const correctFullUrl = `${siteUrl}${pageUrlPath}`; - const ogSlug = `${year}-${month}-${day}-${slug}`; + const ogSlug = slug; const hasOg = hasOgImage(ogSlug); const ogImageUrl = hasOg ? `${siteUrl}/og/${ogSlug}.png` diff --git a/lib/og.js b/lib/og.js index ab3e3ad..a682cce 100644 --- a/lib/og.js +++ b/lib/og.js @@ -126,16 +126,15 @@ function formatDate(dateStr) { } /** - * Use the date+slug (e.g., 2024-03-31-my-post) as the OG image slug. - * Matches the canonical permalink structure. + * Use the pure slug (e.g., my-post) as the OG image slug. + * Matches the plain URL structure. */ function toOgSlug(filePath, fm) { - // filePath: content/{type}/{yyyy}-{MM}-{dd}-{slug}.md + // filePath: content/{type}/{slug}.md const filename = basename(filePath); - const match = filename.match(/(\d{4})-(\d{2})-(\d{2})-(.+)\.md$/); + const match = filename.match(/^([\w-]+)\.md$/); if (match) { - const [, year, month, day, slug] = match; - return `${year}-${month}-${day}-${slug}`; + return match[1]; } // fallback: use filename only (without extension) return filename.replace(/\.md$/, "");