mirror of
https://github.com/svemagie/blog-eleventy-indiekit.git
synced 2026-04-02 08:44:56 +02:00
feat: add /updated.xml feed for recently edited posts
New RSS feed at /updated.xml that surfaces posts where the updated date is newer than the published date. Complements /feed.xml (new posts) with a dedicated feed for edits. - recentlyUpdated collection: filters posts with updated > published, sorted by update date, limited to 20 - Unique guid per edit (url#updated-date) so feed readers treat updates as new entries - Auto-discovery link in <head> and footer link
This commit is contained in:
@@ -102,6 +102,7 @@
|
||||
<link rel="canonical" href="{{ site.url }}{{ page.url }}">
|
||||
<link rel="alternate" type="application/rss+xml" href="/feed.xml" title="RSS Feed">
|
||||
<link rel="alternate" type="application/json" href="/feed.json" title="JSON Feed">
|
||||
<link rel="alternate" type="application/rss+xml" href="/updated.xml" title="Recently Updated — RSS Feed">
|
||||
<link rel="alternate" type="application/rss+xml" href="/digest/feed.xml" title="Weekly Digest — RSS Feed">
|
||||
{% if site.markdownAgents.enabled and page.url and page.url.startsWith('/articles/') and page.url != '/articles/' %}
|
||||
<link rel="alternate" type="text/markdown" href="{{ page.url | stripTrailingSlash }}.md" title="Markdown version">
|
||||
@@ -351,6 +352,7 @@
|
||||
<ul class="space-y-2">
|
||||
<li><a href="/feed.xml" class="text-sm text-surface-600 dark:text-surface-400 hover:text-surface-900 dark:hover:text-surface-100 hover:underline">RSS Feed</a></li>
|
||||
<li><a href="/feed.json" class="text-sm text-surface-600 dark:text-surface-400 hover:text-surface-900 dark:hover:text-surface-100 hover:underline">JSON Feed</a></li>
|
||||
<li><a href="/updated.xml" class="text-sm text-surface-600 dark:text-surface-400 hover:text-surface-900 dark:hover:text-surface-100 hover:underline">Updated Posts Feed</a></li>
|
||||
<li><a href="/changelog/" class="text-sm text-surface-600 dark:text-surface-400 hover:text-surface-900 dark:hover:text-surface-100 hover:underline">Changelog</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -1057,6 +1057,22 @@ export default function (eleventyConfig) {
|
||||
.slice(0, 20);
|
||||
});
|
||||
|
||||
// Recently edited posts (updated !== published) — for /updated.xml
|
||||
eleventyConfig.addCollection("recentlyUpdated", function (collectionApi) {
|
||||
return collectionApi
|
||||
.getFilteredByGlob("content/**/*.md")
|
||||
.filter(isPublished)
|
||||
.filter((item) => {
|
||||
if (!item.data.updated) return false;
|
||||
// Only include if updated date differs from published date
|
||||
const published = new Date(item.date).getTime();
|
||||
const updated = new Date(item.data.updated).getTime();
|
||||
return updated > published;
|
||||
})
|
||||
.sort((a, b) => new Date(b.data.updated) - new Date(a.data.updated))
|
||||
.slice(0, 20);
|
||||
});
|
||||
|
||||
// Categories collection - deduplicated by slug to avoid duplicate permalinks
|
||||
eleventyConfig.addCollection("categories", function (collectionApi) {
|
||||
const categoryMap = new Map(); // slug -> original name (first seen)
|
||||
|
||||
45
updated-feed.njk
Normal file
45
updated-feed.njk
Normal file
@@ -0,0 +1,45 @@
|
||||
---
|
||||
permalink: /updated.xml
|
||||
eleventyExcludeFromCollections: true
|
||||
eleventyImport:
|
||||
collections:
|
||||
- recentlyUpdated
|
||||
---
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">
|
||||
<channel>
|
||||
<title>{{ site.name }} — Recently Updated</title>
|
||||
<link>{{ site.url }}/</link>
|
||||
<description>Posts recently edited on {{ site.name }}</description>
|
||||
<language>{{ site.locale | default('en') }}</language>
|
||||
<atom:link href="{{ site.url }}/updated.xml" rel="self" type="application/rss+xml"/>
|
||||
<atom:link href="https://websubhub.com/hub" rel="hub"/>
|
||||
{%- if collections.recentlyUpdated.length %}
|
||||
<lastBuildDate>{{ collections.recentlyUpdated[0].data.updated | dateToRfc822 }}</lastBuildDate>
|
||||
{%- endif %}
|
||||
{%- for post in collections.recentlyUpdated %}
|
||||
{%- set absolutePostUrl = site.url + post.url %}
|
||||
{%- set postImage = post.data.photo %}
|
||||
{%- if postImage %}
|
||||
{%- 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>
|
||||
<title>{{ post.data.title | default(post.content | striptags | truncate(80)) | escape }} [updated]</title>
|
||||
<link>{{ absolutePostUrl }}</link>
|
||||
<guid isPermaLink="false">{{ absolutePostUrl }}#updated-{{ post.data.updated | dateToRfc822 }}</guid>
|
||||
<pubDate>{{ post.data.updated | dateToRfc822 }}</pubDate>
|
||||
<description>{{ post.content | htmlToAbsoluteUrls(absolutePostUrl) | escape }}</description>
|
||||
{%- if postImage and postImage != "" and (postImage | length) > 10 %}
|
||||
{%- set imageUrl = postImage | url | absoluteUrl(site.url) %}
|
||||
<enclosure url="{{ imageUrl }}" type="image/jpeg" length="0"/>
|
||||
<media:content url="{{ imageUrl }}" medium="image"/>
|
||||
{%- endif %}
|
||||
</item>
|
||||
{%- endfor %}
|
||||
</channel>
|
||||
</rss>
|
||||
Reference in New Issue
Block a user