fix: coerce frontmatter updated string to Date before dateToRfc3339
Build & Deploy / build-and-deploy (push) Successful in 1m48s

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 <noreply@anthropic.com>
This commit is contained in:
svemagie
2026-04-11 17:54:45 +02:00
parent 819aab1883
commit a236ab8b2d
3 changed files with 9 additions and 2 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ permalink: "categories/{{ categoryFeed.slug }}/feed.json"
"content_html": {{ post.content | htmlToAbsoluteUrls(absolutePostUrl) | jsonEncode | safe }}, "content_html": {{ post.content | htmlToAbsoluteUrls(absolutePostUrl) | jsonEncode | safe }},
"content_text": {{ post.content | striptags | jsonEncode | safe }}, "content_text": {{ post.content | striptags | jsonEncode | safe }},
"date_published": "{{ post.date | dateToRfc3339 }}", "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 %}, {%- if postImage and postImage != "" and (postImage | length) > 10 %},
"image": "{{ postImage | url | absoluteUrl(site.url) }}" "image": "{{ postImage | url | absoluteUrl(site.url) }}"
{%- endif %} {%- endif %}
+7
View File
@@ -291,6 +291,13 @@ export default function (eleventyConfig) {
return pluginRss.dateToRfc2822(date); 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. // Embed Everything - auto-embed YouTube, Vimeo, Bluesky, Mastodon, etc.
// YouTube uses lite-yt-embed facade: shows thumbnail + play button, // YouTube uses lite-yt-embed facade: shows thumbnail + play button,
// only loads full iframe on click (~800 KiB savings). // only loads full iframe on click (~800 KiB savings).
+1 -1
View File
@@ -54,7 +54,7 @@ eleventyImport:
"content_html": {{ (post.content | htmlToAbsoluteUrls(absolutePostUrl) + _jsonPixel) | jsonEncode | safe }}, "content_html": {{ (post.content | htmlToAbsoluteUrls(absolutePostUrl) + _jsonPixel) | jsonEncode | safe }},
"content_text": {{ post.content | striptags | jsonEncode | safe }}, "content_text": {{ post.content | striptags | jsonEncode | safe }},
"date_published": "{{ post.date | dateToRfc3339 }}", "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 %}, {%- if postImage and postImage != "" and (postImage | length) > 10 %},
"image": "{{ postImage | url | absoluteUrl(site.url) }}" "image": "{{ postImage | url | absoluteUrl(site.url) }}"
{%- endif %} {%- endif %}