From a236ab8b2d3bd1accf14eb3cf4a2cd3111130634 Mon Sep 17 00:00:00 2001 From: svemagie <869694+svemagie@users.noreply.github.com> Date: Sat, 11 Apr 2026 17:54:45 +0200 Subject: [PATCH] fix: coerce frontmatter `updated` string to Date before dateToRfc3339 Eleventy only auto-converts the `date` key to a Date object; custom fields like `updated` remain ISO strings. Passing them directly to dateToRfc3339 (which calls .toISOString()) throws a TypeError. Add a `toDate` filter and pipe through it in both JSON feed templates. Co-Authored-By: Claude Sonnet 4.6 --- category-feed-json.njk | 2 +- eleventy.config.js | 7 +++++++ feed-json.njk | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/category-feed-json.njk b/category-feed-json.njk index 7036984..c684207 100644 --- a/category-feed-json.njk +++ b/category-feed-json.njk @@ -56,7 +56,7 @@ permalink: "categories/{{ categoryFeed.slug }}/feed.json" "content_html": {{ post.content | htmlToAbsoluteUrls(absolutePostUrl) | jsonEncode | safe }}, "content_text": {{ post.content | striptags | jsonEncode | safe }}, "date_published": "{{ post.date | dateToRfc3339 }}", - "date_modified": "{{ (post.data.updated or post.date) | dateToRfc3339 }}" + "date_modified": "{{ (post.data.updated or post.date) | toDate | dateToRfc3339 }}" {%- if postImage and postImage != "" and (postImage | length) > 10 %}, "image": "{{ postImage | url | absoluteUrl(site.url) }}" {%- endif %} diff --git a/eleventy.config.js b/eleventy.config.js index 4bbc3da..3bc9028 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -291,6 +291,13 @@ export default function (eleventyConfig) { return pluginRss.dateToRfc2822(date); }); + // Coerce a value to a Date object (handles ISO strings from frontmatter like `updated:`) + eleventyConfig.addFilter("toDate", (value) => { + if (!value) return null; + if (value instanceof Date) return value; + return new Date(value); + }); + // Embed Everything - auto-embed YouTube, Vimeo, Bluesky, Mastodon, etc. // YouTube uses lite-yt-embed facade: shows thumbnail + play button, // only loads full iframe on click (~800 KiB savings). diff --git a/feed-json.njk b/feed-json.njk index 9ebdaad..9b13d3e 100644 --- a/feed-json.njk +++ b/feed-json.njk @@ -54,7 +54,7 @@ eleventyImport: "content_html": {{ (post.content | htmlToAbsoluteUrls(absolutePostUrl) + _jsonPixel) | jsonEncode | safe }}, "content_text": {{ post.content | striptags | jsonEncode | safe }}, "date_published": "{{ post.date | dateToRfc3339 }}", - "date_modified": "{{ (post.data.updated or post.date) | dateToRfc3339 }}" + "date_modified": "{{ (post.data.updated or post.date) | toDate | dateToRfc3339 }}" {%- if postImage and postImage != "" and (postImage | length) > 10 %}, "image": "{{ postImage | url | absoluteUrl(site.url) }}" {%- endif %}