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;
// 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`
+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.
* 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$/, "");