From 0627a663c23fdc001288013237c343037f9f17b5 Mon Sep 17 00:00:00 2001 From: Ricardo Date: Wed, 28 Jan 2026 17:45:42 +0100 Subject: [PATCH] fix: handle photo array in feed templates The photo property can be an array of URLs for multi-photo posts. Check if first element looks like a URL (length > 10) to detect arrays. Co-Authored-By: Claude Opus 4.5 --- feed-json.njk | 13 +++++++++++-- feed.njk | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/feed-json.njk b/feed-json.njk index 9f42697..352e13a 100644 --- a/feed-json.njk +++ b/feed-json.njk @@ -18,14 +18,23 @@ eleventyExcludeFromCollections: true "items": [ {%- for post in collections.feed %} {%- set absolutePostUrl = site.url + post.url %} - {%- set postImage = post.data.photo or post.data.image or (post.content | extractFirstImage) %} + {%- set postImage = post.data.photo %} + {%- if postImage %} + {# If photo is an array, use first element (check if first element looks like a URL) #} + {%- if postImage[0] and (postImage[0] | length) > 10 %} + {%- set postImage = postImage[0] %} + {%- endif %} + {%- endif %} + {%- if not postImage or postImage == "" %} + {%- set postImage = post.data.image or (post.content | extractFirstImage) %} + {%- endif %} { "id": "{{ absolutePostUrl }}", "url": "{{ absolutePostUrl }}", "title": {{ post.data.title | default(post.content | striptags | truncate(80)) | jsonEncode | safe }}, "content_html": {{ post.content | htmlToAbsoluteUrls(absolutePostUrl) | jsonEncode | safe }}, "date_published": "{{ post.date | dateToRfc3339 }}" - {%- if postImage and postImage != "" %}, + {%- if postImage and postImage != "" and (postImage | length) > 10 %}, "image": "{{ postImage | url | absoluteUrl(site.url) }}" {%- endif %} }{% if not loop.last %},{% endif %} diff --git a/feed.njk b/feed.njk index e867fef..5a65275 100644 --- a/feed.njk +++ b/feed.njk @@ -13,14 +13,23 @@ eleventyExcludeFromCollections: true {{ collections.feed | getNewestCollectionItemDate | dateToRfc822 }} {%- for post in collections.feed %} {%- set absolutePostUrl = site.url + post.url %} - {%- set postImage = post.data.photo or post.data.image or (post.content | extractFirstImage) %} + {%- set postImage = post.data.photo %} + {%- if postImage %} + {# If photo is an array, use first element (check if first element looks like a URL) #} + {%- if postImage[0] and (postImage[0] | length) > 10 %} + {%- set postImage = postImage[0] %} + {%- endif %} + {%- endif %} + {%- if not postImage or postImage == "" %} + {%- set postImage = post.data.image or (post.content | extractFirstImage) %} + {%- endif %} {{ post.data.title | default(post.content | striptags | truncate(80)) | escape }} {{ absolutePostUrl }} {{ absolutePostUrl }} {{ post.date | dateToRfc822 }} {{ post.content | htmlToAbsoluteUrls(absolutePostUrl) | escape }} - {%- if postImage and postImage != "" %} + {%- if postImage and postImage != "" and (postImage | length) > 10 %} {%- set imageUrl = postImage | url | absoluteUrl(site.url) %}