From 8532492c61461cae42a13c99df0211164a76609a Mon Sep 17 00:00:00 2001
From: Christopher Doohan <chrisdoohan@gmail.com>
Date: Sun, 30 Jun 2024 14:52:42 -0700
Subject: [PATCH] Add xmlns:atom and atom:link to RSS, for compatibility

---
 svekyll/cli.js    | 13 ++++++++++---
 tests/rss_test.js |  7 ++++++-
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/svekyll/cli.js b/svekyll/cli.js
index c18389d..9eadef0 100644
--- a/svekyll/cli.js
+++ b/svekyll/cli.js
@@ -589,21 +589,28 @@ function disableSvekyllAttribution(config) {
 }
 
 export async function generateRss({ files, config }) {
-    
+
     let { limit, include_body, truncate } = config.rss;
     if (!limit) {
 	limit = DEFAULT_LIMIT;
     }
-    
+
     const xw = new XMLWriter;
     xw.startDocument();
     xw
-	.startElement('rss').writeAttribute('version', '2.0')
+	.startElement('rss').writeAttribute('version', '2.0').writeAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom')
 	.startElement('channel');
     config.description && xw.writeElement('description', config.description );
     config.title && xw.writeElement('title', config.title );
+
     if (config.rss.link) {
 	xw.writeElement('link', config.rss.link );
+
+	xw.startElement('atom:link')
+	.writeAttribute('href', `${config.rss.link}/${config.rss.filename}`)
+	.writeAttribute('rel', 'self')
+	.writeAttribute('type', 'application/rss+xml')
+	.endElement();
     } else {
 	error(
 	    'Error, you must provide config.rss.link to provide the full URL for RSS feeds');
diff --git a/tests/rss_test.js b/tests/rss_test.js
index 725d6d4..275d409 100644
--- a/tests/rss_test.js
+++ b/tests/rss_test.js
@@ -186,7 +186,6 @@ OK.
 						const result = await parser.parseStringPromise(rss);
 						const data = result.rss.channel[0];
 
-						expect(data.item.length).toBe(3);
 						expect(data.generator[0].includes('Svekyll')).toBe(true);
 						expect(data
 									 .item[0]
@@ -195,6 +194,12 @@ OK.
 								.toBe(true);
 						expect(result.rss['$'].version).toBe('2.0');
 
+						// xmlns must be present for interop
+						expect(result.rss['$']['xmlns:atom']).toBe('http://www.w3.org/2005/Atom');
+						expect(result.rss.channel[0]['atom:link'][0]['$']['href'])
+								.toBe('https://foobar.com/feed.rss');
+
+						expect(data.item.length).toBe(3);
 						// pubDate must be an RFC-822 date-time
 						const pubDate = data.item[0].pubDate[0].replace(/[\r\n]/g, '').trim();
 						expect(pubDate).toMatch(/^\w{3}, \d{2} \w{3} \d{4} \d{2}:\d{2}:\d{2}/);
-- 
GitLab