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 <noreply@anthropic.com>
This commit is contained in:
+11
-2
@@ -18,14 +18,23 @@ eleventyExcludeFromCollections: true
|
|||||||
"items": [
|
"items": [
|
||||||
{%- for post in collections.feed %}
|
{%- for post in collections.feed %}
|
||||||
{%- set absolutePostUrl = site.url + post.url %}
|
{%- 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 }}",
|
"id": "{{ absolutePostUrl }}",
|
||||||
"url": "{{ absolutePostUrl }}",
|
"url": "{{ absolutePostUrl }}",
|
||||||
"title": {{ post.data.title | default(post.content | striptags | truncate(80)) | jsonEncode | safe }},
|
"title": {{ post.data.title | default(post.content | striptags | truncate(80)) | jsonEncode | safe }},
|
||||||
"content_html": {{ post.content | htmlToAbsoluteUrls(absolutePostUrl) | jsonEncode | safe }},
|
"content_html": {{ post.content | htmlToAbsoluteUrls(absolutePostUrl) | jsonEncode | safe }},
|
||||||
"date_published": "{{ post.date | dateToRfc3339 }}"
|
"date_published": "{{ post.date | dateToRfc3339 }}"
|
||||||
{%- if postImage and postImage != "" %},
|
{%- if postImage and postImage != "" and (postImage | length) > 10 %},
|
||||||
"image": "{{ postImage | url | absoluteUrl(site.url) }}"
|
"image": "{{ postImage | url | absoluteUrl(site.url) }}"
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
}{% if not loop.last %},{% endif %}
|
}{% if not loop.last %},{% endif %}
|
||||||
|
|||||||
@@ -13,14 +13,23 @@ eleventyExcludeFromCollections: true
|
|||||||
<lastBuildDate>{{ collections.feed | getNewestCollectionItemDate | dateToRfc822 }}</lastBuildDate>
|
<lastBuildDate>{{ collections.feed | getNewestCollectionItemDate | dateToRfc822 }}</lastBuildDate>
|
||||||
{%- for post in collections.feed %}
|
{%- for post in collections.feed %}
|
||||||
{%- set absolutePostUrl = site.url + post.url %}
|
{%- 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 %}
|
||||||
<item>
|
<item>
|
||||||
<title>{{ post.data.title | default(post.content | striptags | truncate(80)) | escape }}</title>
|
<title>{{ post.data.title | default(post.content | striptags | truncate(80)) | escape }}</title>
|
||||||
<link>{{ absolutePostUrl }}</link>
|
<link>{{ absolutePostUrl }}</link>
|
||||||
<guid isPermaLink="true">{{ absolutePostUrl }}</guid>
|
<guid isPermaLink="true">{{ absolutePostUrl }}</guid>
|
||||||
<pubDate>{{ post.date | dateToRfc822 }}</pubDate>
|
<pubDate>{{ post.date | dateToRfc822 }}</pubDate>
|
||||||
<description>{{ post.content | htmlToAbsoluteUrls(absolutePostUrl) | escape }}</description>
|
<description>{{ post.content | htmlToAbsoluteUrls(absolutePostUrl) | escape }}</description>
|
||||||
{%- if postImage and postImage != "" %}
|
{%- if postImage and postImage != "" and (postImage | length) > 10 %}
|
||||||
{%- set imageUrl = postImage | url | absoluteUrl(site.url) %}
|
{%- set imageUrl = postImage | url | absoluteUrl(site.url) %}
|
||||||
<enclosure url="{{ imageUrl }}" type="image/jpeg" length="0"/>
|
<enclosure url="{{ imageUrl }}" type="image/jpeg" length="0"/>
|
||||||
<media:content url="{{ imageUrl }}" medium="image"/>
|
<media:content url="{{ imageUrl }}" medium="image"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user