build: 🔧 use manual feed template instead of virtual one

In order to display the title image in the feed.xml like in the posts on the website, a more customizable variant is needed.
This commit is contained in:
Sebin Nyshkim 2025-04-20 22:30:14 +02:00
parent 769063f3cd
commit 1607d31beb
2 changed files with 42 additions and 19 deletions

View file

@ -1,7 +1,6 @@
import fs from 'node:fs';
import { env } from 'node:process';
import { eleventyImageTransformPlugin } from '@11ty/eleventy-img';
import { feedPlugin } from '@11ty/eleventy-plugin-rss';
import Image from '@11ty/eleventy-img';
import eleventyPluginCiu from '@alexcarpenter/eleventy-plugin-caniuse';
import eleventyPluginEmbedEverything from 'eleventy-plugin-embed-everything';
@ -12,6 +11,7 @@ import eleventyPluginNavigation from '@11ty/eleventy-navigation';
import eleventyPluginOgImage from 'eleventy-plugin-og-image';
import eleventyPluginReadingTime from '@myxotod/eleventy-plugin-readingtime';
import eleventyPluginRobotsTxt from 'eleventy-plugin-robotstxt';
import eleventyPluginRss from '@11ty/eleventy-plugin-rss';
import eleventyPluginSyntaxHighlight from '@11ty/eleventy-plugin-syntaxhighlight';
import markdownIt from 'markdown-it';
import markdownItAbbr from 'markdown-it-abbr';
@ -111,24 +111,7 @@ export default async function (eleventyConfig) {
sizes: '(min-width: 1280px) 960px, (min-width: 1024px) 768px, (min-width: 640px) 640px, 480px'
}
});
eleventyConfig.addPlugin(feedPlugin, {
type: 'atom', // or "rss", "json"
outputPath: '/feed.xml',
collection: {
name: 'posts', // iterate over `collections.posts`
limit: 0 // 0 means no limit
},
metadata: {
language: 'en',
title: "Sebin's Blog",
subtitle: 'Writing about stuff I have vague interests in and commenting on stuff I read.',
base: 'https://blog.sebin-nyshkim.net/',
author: {
name: 'Sebin Nyshkim',
email: '' // Optional
}
}
});
eleventyConfig.addPlugin(eleventyPluginRss);
eleventyConfig.setLibrary('md', markdownIt(MARKDOWNIT_OPTIONS));

40
src/feed.njk Normal file
View file

@ -0,0 +1,40 @@
---json
{
"permalink": "feed.xml",
"eleventyExcludeFromCollections": true,
"metadata": {
"title": "Sebin's Blog",
"description": "Writing about stuff I have vague interests in and commenting on stuff I read.",
"language": "en",
"base": "https://blog.sebin-nyshkim.net/",
"author": {
"name": "Sebin Nyshkim"
}
}
}
---
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="{{ metadata.language or page.lang }}">
<title>{{ metadata.title }}</title>
<subtitle>{{ metadata.description }}</subtitle>
<link href="{{ permalink | htmlBaseUrl(metadata.base) }}" rel="self"/>
<link href="{{ metadata.base | addPathPrefixToFullUrl }}"/>
<updated>{{ collections.posts | getNewestCollectionItemDate | dateToRfc3339 }}</updated>
<id>{{ metadata.base | addPathPrefixToFullUrl }}</id>
<author>
<name>{{ metadata.author.name }}</name>
</author>
{%- for post in collections.posts | reverse %}
{%- set absolutePostUrl %}{{ post.url | htmlBaseUrl(metadata.base) }}{% endset %}
<entry>
<title>{{ post.data.title }}</title>
<link href="{{ absolutePostUrl }}"/>
<updated>{{ post.date | dateToRfc3339 }}</updated>
<id>{{ absolutePostUrl }}</id>
<content type="html">
&lt;img src="{{ post.data.image.src }}.webp?width=1200" alt="{{ post.data.image.alt }}"&gt;
{{ post.content | renderTransforms(post.data.page, metadata.base) }}
</content>
</entry>
{%- endfor %}
</feed>