diff --git a/_data/eleventyComputed.js b/_data/eleventyComputed.js index fa56636..7ef08a2 100644 --- a/_data/eleventyComputed.js +++ b/_data/eleventyComputed.js @@ -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 diff --git a/_includes/layouts/page.njk b/_includes/layouts/page.njk index dae7781..e5c7318 100644 --- a/_includes/layouts/page.njk +++ b/_includes/layouts/page.njk @@ -15,9 +15,10 @@ withSidebar: true {{ summary }}
{% endif %} - {% if updated %} + {% set lastUpdated = updated or page.date %} + {% if lastUpdated %}- Last updated: + Last updated:
{% endif %} diff --git a/content/content.11tydata.js b/content/content.11tydata.js index 03f3c6c..2b485b5 100644 --- a/content/content.11tydata.js +++ b/content/content.11tydata.js @@ -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", -}; \ No newline at end of file + eleventyComputed: { + permalink: (data) => normalizePermalink(data.permalink), + }, +}; diff --git a/content/pages/now.md b/content/pages/now.md index c81fc94..467cf01 100644 --- a/content/pages/now.md +++ b/content/pages/now.md @@ -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 diff --git a/theme/_data/eleventyComputed.js b/theme/_data/eleventyComputed.js index fa56636..7ef08a2 100644 --- a/theme/_data/eleventyComputed.js +++ b/theme/_data/eleventyComputed.js @@ -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 diff --git a/theme/_includes/layouts/page.njk b/theme/_includes/layouts/page.njk index 5dc14a6..a03e386 100644 --- a/theme/_includes/layouts/page.njk +++ b/theme/_includes/layouts/page.njk @@ -15,9 +15,10 @@ withSidebar: true {{ summary }} {% endif %} - {% if updated %} -- Last updated: + {% set lastUpdated = updated or page.date %} + {% if lastUpdated %} +
+ Last updated:
{% endif %}