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