fix: og image fixes
Build & Deploy / build-and-deploy (push) Successful in 1m16s

This commit is contained in:
svemagie
2026-03-31 19:24:58 +02:00
parent c40456bcae
commit ba9e64ae9e
2 changed files with 10 additions and 11 deletions
+5 -5
View File
@@ -403,16 +403,16 @@ export default function (eleventyConfig) {
if (!outputPath || !outputPath.endsWith(".html")) return content; if (!outputPath || !outputPath.endsWith(".html")) return content;
// Derive correct page URL and OG slug from outputPath (immune to race condition) // 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( const postMatch = outputPath.match(
/\/([\w-]+)\/(\d{4})\/(\d{2})\/(\d{2})\/([\w-]+)\/index\.html$/ /\/([\w-]+)\/([\w-]+)\/index\.html$/
); );
if (postMatch) { if (postMatch) {
const [, type, year, month, day, slug] = postMatch; const [, type, slug] = postMatch;
const pageUrlPath = `/${type}/${year}/${month}/${day}/${slug}/`; const pageUrlPath = `/${type}/${slug}/`;
const correctFullUrl = `${siteUrl}${pageUrlPath}`; const correctFullUrl = `${siteUrl}${pageUrlPath}`;
const ogSlug = `${year}-${month}-${day}-${slug}`; const ogSlug = slug;
const hasOg = hasOgImage(ogSlug); const hasOg = hasOgImage(ogSlug);
const ogImageUrl = hasOg const ogImageUrl = hasOg
? `${siteUrl}/og/${ogSlug}.png` ? `${siteUrl}/og/${ogSlug}.png`
+5 -6
View File
@@ -126,16 +126,15 @@ function formatDate(dateStr) {
} }
/** /**
* Use the date+slug (e.g., 2024-03-31-my-post) as the OG image slug. * Use the pure slug (e.g., my-post) as the OG image slug.
* Matches the canonical permalink structure. * Matches the plain URL structure.
*/ */
function toOgSlug(filePath, fm) { function toOgSlug(filePath, fm) {
// filePath: content/{type}/{yyyy}-{MM}-{dd}-{slug}.md // filePath: content/{type}/{slug}.md
const filename = basename(filePath); const filename = basename(filePath);
const match = filename.match(/(\d{4})-(\d{2})-(\d{2})-(.+)\.md$/); const match = filename.match(/^([\w-]+)\.md$/);
if (match) { if (match) {
const [, year, month, day, slug] = match; return match[1];
return `${year}-${month}-${day}-${slug}`;
} }
// fallback: use filename only (without extension) // fallback: use filename only (without extension)
return filename.replace(/\.md$/, ""); return filename.replace(/\.md$/, "");