Simplify the Atom and JSON feeds

This commit is contained in:
Zach Leatherman 2022-07-15 14:42:48 -05:00
parent 294f4c53c1
commit c780c72770
3 changed files with 12 additions and 25 deletions

View File

@ -3,16 +3,6 @@
"url": "https://example.com/", "url": "https://example.com/",
"language": "en", "language": "en",
"description": "I am writing about my experiences as a naval navel-gazer.", "description": "I am writing about my experiences as a naval navel-gazer.",
"feed": {
"subtitle": "I am writing about my experiences as a naval navel-gazer.",
"filename": "feed.xml",
"path": "/feed/feed.xml",
"id": "https://example.com/"
},
"jsonfeed": {
"path": "/feed/feed.json",
"url": "https://example.com/feed/feed.json"
},
"author": { "author": {
"name": "Your Name Here", "name": "Your Name Here",
"email": "youremailaddress@example.com", "email": "youremailaddress@example.com",

View File

@ -1,16 +1,15 @@
--- ---
# Metadata comes from _data/metadata.json # Metadata comes from _data/metadata.json
permalink: "{{ metadata.feed.path }}" permalink: /feed/feed.xml
--- ---
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"> <feed xmlns="http://www.w3.org/2005/Atom" xml:base="{{ metadata.language }}">
<title>{{ metadata.title }}</title> <title>{{ metadata.title }}</title>
<subtitle>{{ metadata.feed.subtitle }}</subtitle> <subtitle>{{ metadata.description }}</subtitle>
{% set absoluteUrl %}{{ metadata.feed.path | url | absoluteUrl(metadata.url) }}{% endset %} <link href="{{ permalink | url | absoluteUrl(metadata.url) }}" rel="self"/>
<link href="{{ absoluteUrl }}" rel="self"/>
<link href="{{ metadata.url }}"/> <link href="{{ metadata.url }}"/>
<updated>{{ collections.posts | rssLastUpdatedDate }}</updated> <updated>{{ collections.posts | getNewestCollectionItemDate | dateToRfc3339 }}</updated>
<id>{{ metadata.feed.id }}</id> <id>{{ metadata.url }}</id>
<author> <author>
<name>{{ metadata.author.name }}</name> <name>{{ metadata.author.name }}</name>
<email>{{ metadata.author.email }}</email> <email>{{ metadata.author.email }}</email>
@ -20,7 +19,7 @@ permalink: "{{ metadata.feed.path }}"
<entry> <entry>
<title>{{ post.data.title }}</title> <title>{{ post.data.title }}</title>
<link href="{{ absolutePostUrl }}"/> <link href="{{ absolutePostUrl }}"/>
<updated>{{ post.date | rssDate }}</updated> <updated>{{ post.date | dateToRfc3339 }}</updated>
<id>{{ absolutePostUrl }}</id> <id>{{ absolutePostUrl }}</id>
<content type="html">{{ post.templateContent | htmlToAbsoluteUrls(absolutePostUrl) }}</content> <content type="html">{{ post.templateContent | htmlToAbsoluteUrls(absolutePostUrl) }}</content>
</entry> </entry>

View File

@ -1,13 +1,13 @@
--- ---
# Metadata comes from _data/metadata.json # Metadata comes from _data/metadata.json
permalink: "{{ metadata.jsonfeed.path }}" permalink: /feed/feed.json
--- ---
{ {
"version": "https://jsonfeed.org/version/1.1", "version": "https://jsonfeed.org/version/1.1",
"title": "{{ metadata.title }}", "title": "{{ metadata.title }}",
"language": "{{ metadata.language }}", "language": "{{ metadata.language }}",
"home_page_url": "{{ metadata.url }}", "home_page_url": "{{ metadata.url }}",
"feed_url": "{{ metadata.jsonfeed.url }}", "feed_url": "{{ permalink | url | absoluteUrl(metadata.url) }}",
"description": "{{ metadata.description }}", "description": "{{ metadata.description }}",
"author": { "author": {
"name": "{{ metadata.author.name }}", "name": "{{ metadata.author.name }}",
@ -15,17 +15,15 @@ permalink: "{{ metadata.jsonfeed.path }}"
}, },
"items": [ "items": [
{%- for post in collections.posts | reverse %} {%- for post in collections.posts | reverse %}
{%- set absolutePostUrl %}{{ post.url | url | absoluteUrl(metadata.url) }}{% endset -%} {%- set absolutePostUrl = post.url | url | absoluteUrl(metadata.url) %}
{ {
"id": "{{ absolutePostUrl }}", "id": "{{ absolutePostUrl }}",
"url": "{{ absolutePostUrl }}", "url": "{{ absolutePostUrl }}",
"title": "{{ post.data.title }}", "title": "{{ post.data.title }}",
"content_html": {% if post.templateContent %}{{ post.templateContent | htmlToAbsoluteUrls(absolutePostUrl) | dump | safe }}{% else %}""{% endif %}, "content_html": {% if post.templateContent %}{{ post.templateContent | htmlToAbsoluteUrls(absolutePostUrl) | dump | safe }}{% else %}""{% endif %},
"date_published": "{{ post.date | rssDate }}" "date_published": "{{ post.date | dateToRfc3339 }}"
} }
{%- if not loop.last -%} {% if not loop.last %},{% endif %}
,
{%- endif -%}
{%- endfor %} {%- endfor %}
] ]
} }