fix: normalize permalinks and page updated dates
This commit is contained in:
@@ -15,14 +15,33 @@
|
||||
* See: https://github.com/11ty/eleventy/issues/3183
|
||||
*/
|
||||
|
||||
const normalizeOutputPermalink = (permalink) => {
|
||||
if (typeof permalink !== "string") return permalink;
|
||||
|
||||
// Convert accidental absolute URLs to Eleventy output paths.
|
||||
if (/^https?:\/\//i.test(permalink)) {
|
||||
try {
|
||||
const { pathname } = new URL(permalink);
|
||||
if (!pathname) return "/";
|
||||
return pathname.endsWith("/") ? pathname : `${pathname}/`;
|
||||
} catch {
|
||||
return permalink;
|
||||
}
|
||||
}
|
||||
|
||||
return permalink;
|
||||
};
|
||||
|
||||
export default {
|
||||
eleventyComputed: {
|
||||
// Compute permalink from file path for posts without explicit frontmatter permalink.
|
||||
// Pattern: content/{type}/{yyyy}-{MM}-{dd}-{slug}.md → /{type}/{yyyy}/{MM}/{dd}/{slug}/
|
||||
permalink: (data) => {
|
||||
// Convert stale /content/ permalinks from pre-beta.37 posts to canonical format
|
||||
if (data.permalink && typeof data.permalink === "string") {
|
||||
const contentMatch = data.permalink.match(
|
||||
const explicitPermalink = normalizeOutputPermalink(data.permalink);
|
||||
|
||||
if (explicitPermalink && typeof explicitPermalink === "string") {
|
||||
const contentMatch = explicitPermalink.match(
|
||||
/^\/content\/([^/]+)\/(\d{4})-(\d{2})-(\d{2})-(.+?)\/?$/
|
||||
);
|
||||
if (contentMatch) {
|
||||
@@ -30,7 +49,7 @@ export default {
|
||||
return `/${type}/${year}/${month}/${day}/${slug}/`;
|
||||
}
|
||||
// Valid non-/content/ permalink — use as-is
|
||||
return data.permalink;
|
||||
return explicitPermalink;
|
||||
}
|
||||
|
||||
// No frontmatter permalink — compute from file path
|
||||
|
||||
@@ -15,9 +15,10 @@ withSidebar: true
|
||||
{{ summary }}
|
||||
</p>
|
||||
{% endif %}
|
||||
{% if updated %}
|
||||
{% set lastUpdated = updated or page.date %}
|
||||
{% if lastUpdated %}
|
||||
<p class="text-sm text-surface-600 dark:text-surface-400 mt-2">
|
||||
Last updated: <time class="dt-updated font-mono text-sm" datetime="{{ updated | isoDate }}">{{ updated | dateDisplay }}</time>
|
||||
Last updated: <time class="dt-updated font-mono text-sm" datetime="{{ lastUpdated | isoDate }}">{{ lastUpdated | dateDisplay }}</time>
|
||||
</p>
|
||||
{% endif %}
|
||||
</header>
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
const normalizePermalink = (permalink) => {
|
||||
if (typeof permalink !== "string") return permalink;
|
||||
|
||||
if (/^https?:\/\//i.test(permalink)) {
|
||||
try {
|
||||
const { pathname } = new URL(permalink);
|
||||
if (!pathname) return "/";
|
||||
return pathname.endsWith("/") ? pathname : `${pathname}/`;
|
||||
} catch {
|
||||
return permalink;
|
||||
}
|
||||
}
|
||||
|
||||
return permalink;
|
||||
};
|
||||
|
||||
export default {
|
||||
layout: "layouts/post.njk",
|
||||
};
|
||||
eleventyComputed: {
|
||||
permalink: (data) => normalizePermalink(data.permalink),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -5,10 +5,10 @@ summary: a page that tells you what I'm focused on at this point in my life
|
||||
category:
|
||||
- now
|
||||
- slashpage
|
||||
permalink: https://blog.giersig.eu/now/
|
||||
permalink: /now/
|
||||
---
|
||||
|
||||
This page is a now page, you should consider adding one if you have a website as well, inspiration comes from here
|
||||
|
||||
## personal
|
||||
This page is a now page, you should consider adding one if you have a website as well, inspiration comes from here
|
||||
|
||||
## personal
|
||||
what a wild ride
|
||||
|
||||
@@ -15,14 +15,33 @@
|
||||
* See: https://github.com/11ty/eleventy/issues/3183
|
||||
*/
|
||||
|
||||
const normalizeOutputPermalink = (permalink) => {
|
||||
if (typeof permalink !== "string") return permalink;
|
||||
|
||||
// Convert accidental absolute URLs to Eleventy output paths.
|
||||
if (/^https?:\/\//i.test(permalink)) {
|
||||
try {
|
||||
const { pathname } = new URL(permalink);
|
||||
if (!pathname) return "/";
|
||||
return pathname.endsWith("/") ? pathname : `${pathname}/`;
|
||||
} catch {
|
||||
return permalink;
|
||||
}
|
||||
}
|
||||
|
||||
return permalink;
|
||||
};
|
||||
|
||||
export default {
|
||||
eleventyComputed: {
|
||||
// Compute permalink from file path for posts without explicit frontmatter permalink.
|
||||
// Pattern: content/{type}/{yyyy}-{MM}-{dd}-{slug}.md → /{type}/{yyyy}/{MM}/{dd}/{slug}/
|
||||
permalink: (data) => {
|
||||
// Convert stale /content/ permalinks from pre-beta.37 posts to canonical format
|
||||
if (data.permalink && typeof data.permalink === "string") {
|
||||
const contentMatch = data.permalink.match(
|
||||
const explicitPermalink = normalizeOutputPermalink(data.permalink);
|
||||
|
||||
if (explicitPermalink && typeof explicitPermalink === "string") {
|
||||
const contentMatch = explicitPermalink.match(
|
||||
/^\/content\/([^/]+)\/(\d{4})-(\d{2})-(\d{2})-(.+?)\/?$/
|
||||
);
|
||||
if (contentMatch) {
|
||||
@@ -30,7 +49,7 @@ export default {
|
||||
return `/${type}/${year}/${month}/${day}/${slug}/`;
|
||||
}
|
||||
// Valid non-/content/ permalink — use as-is
|
||||
return data.permalink;
|
||||
return explicitPermalink;
|
||||
}
|
||||
|
||||
// No frontmatter permalink — compute from file path
|
||||
|
||||
@@ -15,9 +15,10 @@ withSidebar: true
|
||||
{{ summary }}
|
||||
</p>
|
||||
{% endif %}
|
||||
{% if updated %}
|
||||
<p class="text-sm text-surface-500 dark:text-surface-400 mt-2">
|
||||
Last updated: <time class="dt-updated" datetime="{{ updated | isoDate }}">{{ updated | dateDisplay }}</time>
|
||||
{% set lastUpdated = updated or page.date %}
|
||||
{% if lastUpdated %}
|
||||
<p class="text-sm text-surface-600 dark:text-surface-400 mt-2">
|
||||
Last updated: <time class="dt-updated font-mono text-sm" datetime="{{ lastUpdated | isoDate }}">{{ lastUpdated | dateDisplay }}</time>
|
||||
</p>
|
||||
{% endif %}
|
||||
</header>
|
||||
|
||||
Reference in New Issue
Block a user