Capital/app/feed/route.ts

29 lines
670 B
TypeScript
Raw Normal View History

2024-02-24 10:54:47 +00:00
import RSS from "rss";
import { SITE_DESCRIPTION, SITE_NAME, SITE_URL } from "@/app/consts";
import { getSortedPosts } from "@/content/posts";
export async function GET() {
const feed = new RSS({
title: SITE_NAME,
description: SITE_DESCRIPTION,
site_url: SITE_URL,
feed_url: `${SITE_URL}/feed`,
2024-02-24 13:56:35 +00:00
language: "zh-CN",
2024-02-24 10:54:47 +00:00
});
getSortedPosts().forEach((item) => {
feed.item({
url: `${SITE_URL}/p/${item.id}`,
title: item.title,
description: item.description ?? "No description yet.",
date: item.date,
});
});
return new Response(feed.xml(), {
headers: {
2024-02-24 13:56:35 +00:00
"content-type": "application/xml",
},
2024-02-24 10:54:47 +00:00
});
2024-02-24 13:56:35 +00:00
}