Files
kill-the-news/src/routes/rss.ts
T
Julien Herr 4428f35dd4 fix(feed): add Atom link in emails page, fix HTML stripping, use request URL for self-link
- Add Atom Feed URL to the Feed Details card in the emails page
- Fix extractBodyContent to handle emails without a closing </body> tag
  (regex now falls back to capturing everything after the opening <body>)
- Use the actual request URL origin for atom:link rel="self" in RSS/Atom
  feeds, guaranteeing it always matches the document location regardless
  of how DOMAIN is configured

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-22 18:41:21 +02:00

45 lines
1.3 KiB
TypeScript

import { Context } from "hono";
import { Env } from "../types";
import { generateRssFeed } from "../utils/feed-generator";
import { fetchFeedData } from "../utils/feed-fetcher";
export async function handle(c: Context<{ Bindings: Env }>): Promise<Response> {
try {
const feedId = c.req.param("feedId");
if (!feedId) {
return new Response("Feed ID is required", { status: 400 });
}
const feedData = await fetchFeedData(feedId, c.env, "rss");
if (!feedData) {
return new Response("Feed not found", { status: 404 });
}
const baseUrl = `https://${c.env.DOMAIN}`;
const selfUrl = new URL(c.req.url).origin + `/rss/${feedId}`;
const rssXml = generateRssFeed(
feedData.feedConfig,
feedData.emails,
baseUrl,
feedId,
selfUrl,
);
const linkHeader = [
`<${baseUrl}/hub>; rel="hub"`,
`<${baseUrl}/rss/${feedId}>; rel="self"`,
].join(", ");
return new Response(rssXml, {
status: 200,
headers: {
"Content-Type": "application/rss+xml",
"Cache-Control": "max-age=1800",
Link: linkHeader,
},
});
} catch (error) {
console.error("Error generating RSS feed:", error);
return new Response("Internal Server Error", { status: 500 });
}
}