mirror of
https://github.com/svemagie/blog-eleventy-indiekit.git
synced 2026-04-02 16:44:56 +02:00
fix(og): match Eleventy's page.fileSlug by stripping date prefix
Eleventy v3 parses YYYY-MM-DD- from filenames and removes it from page.fileSlug. The OG generator was using the full filename (with date prefix) causing a slug mismatch — hasOgImage filter checked for 'slug.png' while the file was 'YYYY-MM-DD-slug.png'. Also removes debug logging from hasOgImage filter.
This commit is contained in:
10
lib/og.js
10
lib/og.js
@@ -105,6 +105,14 @@ 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.
|
||||
*/
|
||||
function toEleventySlug(filename) {
|
||||
return filename.replace(/^\d{4}-\d{2}-\d{2}-/, "");
|
||||
}
|
||||
|
||||
function truncateTitle(title, max = 120) {
|
||||
if (!title || title.length <= max) return title || "Untitled";
|
||||
return title.slice(0, max).trim() + "\u2026";
|
||||
@@ -299,7 +307,7 @@ export async function generateOgImages(contentDir, cacheDir, siteName) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const slug = basename(filePath, ".md");
|
||||
const slug = toEleventySlug(basename(filePath, ".md"));
|
||||
const title = fm.title || fm.name || extractBodyText(raw);
|
||||
const date = fm.published || fm.date || "";
|
||||
const postType = detectPostType(filePath);
|
||||
|
||||
Reference in New Issue
Block a user