From 298eafc39c142ab1ef2ffd5efa93694e060e0bf5 Mon Sep 17 00:00:00 2001 From: Jared Watts Date: Thu, 29 Oct 2026 18:21:25 -0700 Subject: [PATCH] Write the RSS feed directly instead of through the feed package The RSS feed is built with the feed package, which pulls in sax through xml-js. sax is licensed under BlueOak-1.0.0, which would be good to remove from the site's dependencies since it's not an approved license. This commit builds the RSS 2.0 XML in pages/feed.xml.tsx and drops feed. The output keeps the same channel fields, items, ordering, and indentation, with titles and descriptions in CDATA and all other text XML-escaped. The channel's element named the feed package, so it was also removed. Signed-off-by: Jared Watts --- package-lock.json | 35 ---------------------- package.json | 1 - pages/feed.xml.tsx | 72 ++++++++++++++++++++++++++++++++-------------- 3 files changed, 51 insertions(+), 57 deletions(-) diff --git a/package-lock.json b/package-lock.json index e4a29bc..5830b49 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,6 @@ "@vercel/analytics": "^2.0.1", "@vercel/og": "^1.0.0", "@vercel/speed-insights": "^2.0.0", - "feed": "^5.2.1", "github-slugger": "^2.0.0", "gray-matter": "^4.0.3", "next": "^16.3.0", @@ -4035,19 +4034,6 @@ "reusify": "^1.0.4" } }, - "node_modules/feed": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/feed/-/feed-5.2.1.tgz", - "integrity": "sha512-jTynzYPWs9ALjro0GW8j7sv9y7cJBeOdD4Y88kVqYy/eyusIX3g+499JiTDIlD9Ge/unebx57T4Uzo6vpYvMtA==", - "license": "MIT", - "dependencies": { - "xml-js": "^1.6.11" - }, - "engines": { - "node": ">=20", - "pnpm": ">=10" - } - }, "node_modules/fflate": { "version": "0.7.5", "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.7.5.tgz", @@ -7709,15 +7695,6 @@ "integrity": "sha512-toUI84YS5YmxW219erniWD0CIVOo46xGKColeNQRgOzDorgBi1v4D71/OFzgD9GO2UGKIv1C3Sp8DAn0+j5w7A==", "license": "MIT" }, - "node_modules/sax": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/sax/-/sax-1.6.0.tgz", - "integrity": "sha512-6R3J5M4AcbtLUdZmRv2SygeVaM7IhrLXu9BmnOGmmACak8fiUtOsYNWUS4uK7upbmHIBbLBeFeI//477BKLBzA==", - "license": "BlueOak-1.0.0", - "engines": { - "node": ">=11.0.0" - } - }, "node_modules/scheduler": { "version": "0.23.2", "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", @@ -8884,18 +8861,6 @@ "node": ">=0.10.0" } }, - "node_modules/xml-js": { - "version": "1.6.11", - "resolved": "https://registry.npmjs.org/xml-js/-/xml-js-1.6.11.tgz", - "integrity": "sha512-7rVi2KMfwfWFl+GpPg6m80IVMWXLRjO+PxTq7V2CDhoGak0wzYzFgUY2m4XJ47OGdXd8eLE8EmwfAmdjw7lC1g==", - "license": "MIT", - "dependencies": { - "sax": "^1.2.4" - }, - "bin": { - "xml-js": "bin/cli.js" - } - }, "node_modules/yallist": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", diff --git a/package.json b/package.json index bac626a..9a89f8e 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ "@vercel/analytics": "^2.0.1", "@vercel/og": "^1.0.0", "@vercel/speed-insights": "^2.0.0", - "feed": "^5.2.1", "github-slugger": "^2.0.0", "gray-matter": "^4.0.3", "next": "^16.3.0", diff --git a/pages/feed.xml.tsx b/pages/feed.xml.tsx index 09dc5b9..ed47a5a 100644 --- a/pages/feed.xml.tsx +++ b/pages/feed.xml.tsx @@ -1,5 +1,4 @@ import type { GetServerSideProps } from 'next' -import { Feed } from 'feed' import { getAllPosts } from '@/lib/blog' import { SITE_URL, SITE_NAME, BLOG_TITLE, BLOG_DESCRIPTION } from '@/lib/site' @@ -8,36 +7,67 @@ export default function Feeds() { return null } +// Escape text for an XML element body or a double-quoted attribute value. +function escapeXml(s: string): string { + return s + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') +} + +// Titles and descriptions are free text from post frontmatter, so they go in +// CDATA. A literal "]]>" would end the section early, so we split it across two. +function cdata(s: string): string { + return `/g, ']]]]>')}]]>` +} + export const getServerSideProps: GetServerSideProps = async ({ res }) => { const posts = getAllPosts() - const feed = new Feed({ - title: BLOG_TITLE, - description: BLOG_DESCRIPTION, - id: `${SITE_URL}/blog`, - link: `${SITE_URL}/blog`, - language: 'en', - favicon: `${SITE_URL}/icon.png`, - copyright: `© ${new Date().getFullYear()} The Modelplane Authors. ${SITE_NAME}™ is a trademark.`, - feedLinks: { rss2: `${SITE_URL}/feed.xml` }, - }) + const channel = [ + `${escapeXml(BLOG_TITLE)}`, + `${escapeXml(`${SITE_URL}/blog`)}`, + `${escapeXml(BLOG_DESCRIPTION)}`, + `${new Date().toUTCString()}`, + `https://validator.w3.org/feed/docs/rss2.html`, + `en`, + `${escapeXml( + `© ${new Date().getFullYear()} The Modelplane Authors. ${SITE_NAME}™ is a trademark.` + )}`, + ] for (const post of posts) { const url = `${SITE_URL}/blog/${post.slug}` - feed.addItem({ - title: post.title, - id: url, - link: url, - description: post.description, - date: new Date(post.date), - image: post.cover ? `${SITE_URL}${post.cover}` : undefined, - author: post.authors.map((a) => ({ name: a.name, link: a.url })), - }) + const item = [ + `${cdata(post.title)}`, + `${escapeXml(url)}`, + `${escapeXml(url)}`, + `${new Date(post.date).toUTCString()}`, + ] + if (post.description) item.push(`${cdata(post.description)}`) + for (const a of post.authors) item.push(`${escapeXml(a.name)}`) + if (post.cover) { + // The enclosure type comes from the cover's file extension (cover.png -> image/png). + const image = `${SITE_URL}${post.cover}` + const ext = new URL(image).pathname.split('.').pop() + item.push(``) + } + channel.push('', ...item.map((line) => ` ${line}`), '') } + const xml = [ + '', + '', + ' ', + ...channel.map((line) => ` ${line}`), + ' ', + '', + ].join('\n') + res.setHeader('Content-Type', 'application/rss+xml; charset=utf-8') res.setHeader('Cache-Control', 'public, s-maxage=3600, stale-while-revalidate=86400') - res.write(feed.rss2()) + res.write(xml) res.end() return { props: {} }