mirror of
https://github.com/svemagie/blog-eleventy-indiekit.git
synced 2026-04-02 08:44:56 +02:00
Add eleventyImport.collections to templates that access collections via Nunjucks loops (not pagination frontmatter). Without this, Eleventy's --incremental mode skips these pages when content changes. - index.njk: posts, feed (homepage recent posts widget) - feed.njk: feed (RSS must update with new posts) - feed-json.njk: feed (JSON feed must update with new posts) - slashes.njk: pages (slash pages index) - categories-index.njk: categories (categories index)
67 lines
2.3 KiB
Plaintext
67 lines
2.3 KiB
Plaintext
---
|
|
permalink: /feed.json
|
|
eleventyExcludeFromCollections: true
|
|
eleventyImport:
|
|
collections:
|
|
- feed
|
|
---
|
|
{
|
|
"version": "https://jsonfeed.org/version/1.1",
|
|
"title": "{{ site.name }}",
|
|
"home_page_url": "{{ site.url }}/",
|
|
"feed_url": "{{ site.url }}/feed.json",
|
|
"hubs": [
|
|
{
|
|
"type": "WebSub",
|
|
"url": "https://websubhub.com/hub"
|
|
}
|
|
],
|
|
"description": "{{ site.description }}",
|
|
"language": "{{ site.locale | default('en') }}",
|
|
"authors": [
|
|
{
|
|
"name": "{{ site.author.name | default(site.name) }}",
|
|
"url": "{{ site.url }}/"
|
|
}
|
|
],
|
|
"_textcasting": {
|
|
"version": "1.0",
|
|
"about": "https://textcasting.org/"
|
|
{%- set hasSupport = site.support and (site.support.url or site.support.stripe or site.support.lightning or site.support.paymentPointer) %}
|
|
{%- if hasSupport %},
|
|
"support": {{ site.support | textcastingSupport | jsonEncode | safe }}
|
|
{%- endif %}
|
|
},
|
|
"items": [
|
|
{%- for post in collections.feed %}
|
|
{%- set absolutePostUrl = site.url + post.url %}
|
|
{%- 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": {% if post.data.title %}{{ post.data.title | jsonEncode | safe }}{% else %}null{% endif %},
|
|
"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 }}"
|
|
{%- if postImage and postImage != "" and (postImage | length) > 10 %},
|
|
"image": "{{ postImage | url | absoluteUrl(site.url) }}"
|
|
{%- endif %}
|
|
{%- set attachments = post.data | feedAttachments %}
|
|
{%- if attachments.length > 0 %},
|
|
"attachments": {{ attachments | jsonEncode | safe }}
|
|
{%- endif %}
|
|
}{% if not loop.last %},{% endif %}
|
|
{%- endfor %}
|
|
]
|
|
}
|