mirror of
https://github.com/svemagie/blog-eleventy-indiekit.git
synced 2026-05-15 15:08:51 +02:00
fix: auto-convert stale /content/ permalinks in data cascade
Posts published between Jan 19 – Feb 6 2026 (pre-beta.37 preset) had permalink: /content/TYPE/YYYY-MM-DD-SLUG/ in frontmatter. The data cascade trusted these values, causing Eleventy to generate pages at /content/ paths instead of canonical URLs. This left 86 posts (including articles like collecteur-de-flux-rss) returning 404 at their canonical URLs. The markdown files were fixed on the server (permalink lines removed), but this adds a safety net: any remaining or future /content/ permalinks are auto-converted to /TYPE/YYYY/MM/DD/SLUG/ format.
This commit is contained in:
@@ -20,10 +20,20 @@ export default {
|
|||||||
// Compute permalink from file path for posts without explicit frontmatter permalink.
|
// Compute permalink from file path for posts without explicit frontmatter permalink.
|
||||||
// Pattern: content/{type}/{yyyy}-{MM}-{dd}-{slug}.md → /{type}/{yyyy}/{MM}/{dd}/{slug}/
|
// Pattern: content/{type}/{yyyy}-{MM}-{dd}-{slug}.md → /{type}/{yyyy}/{MM}/{dd}/{slug}/
|
||||||
permalink: (data) => {
|
permalink: (data) => {
|
||||||
// If frontmatter already has permalink, use it (new posts from preset)
|
// Convert stale /content/ permalinks from pre-beta.37 posts to canonical format
|
||||||
if (data.permalink) return data.permalink;
|
if (data.permalink && typeof data.permalink === "string") {
|
||||||
|
const contentMatch = data.permalink.match(
|
||||||
|
/^\/content\/([^/]+)\/(\d{4})-(\d{2})-(\d{2})-(.+?)\/?$/
|
||||||
|
);
|
||||||
|
if (contentMatch) {
|
||||||
|
const [, type, year, month, day, slug] = contentMatch;
|
||||||
|
return `/${type}/${year}/${month}/${day}/${slug}/`;
|
||||||
|
}
|
||||||
|
// Valid non-/content/ permalink — use as-is
|
||||||
|
return data.permalink;
|
||||||
|
}
|
||||||
|
|
||||||
// Only compute for files matching the dated post pattern
|
// No frontmatter permalink — compute from file path
|
||||||
const inputPath = data.page?.inputPath || "";
|
const inputPath = data.page?.inputPath || "";
|
||||||
const match = inputPath.match(
|
const match = inputPath.match(
|
||||||
/content\/([^/]+)\/(\d{4})-(\d{2})-(\d{2})-(.+)\.md$/
|
/content\/([^/]+)\/(\d{4})-(\d{2})-(\d{2})-(.+)\.md$/
|
||||||
@@ -33,7 +43,7 @@ export default {
|
|||||||
return `/${type}/${year}/${month}/${day}/${slug}/`;
|
return `/${type}/${year}/${month}/${day}/${slug}/`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For non-matching files (pages, root files), preserve existing permalink or let Eleventy decide
|
// For non-matching files (pages, root files), let Eleventy decide
|
||||||
return data.permalink;
|
return data.permalink;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user