This commit is contained in:
+5
-5
@@ -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`
|
||||
|
||||
@@ -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$/, "");
|
||||
|
||||
Reference in New Issue
Block a user