24 lines
705 B
TypeScript
24 lines
705 B
TypeScript
import rss from "@astrojs/rss";
|
|
import { getCollection } from "astro:content";
|
|
import { SITE_TITLE, SITE_DESCRIPTION, SITE_URL } from "@/consts";
|
|
import type { APIContext } from "astro";
|
|
|
|
export const prerender = true;
|
|
|
|
export async function GET(context: APIContext) {
|
|
const posts = await getCollection("blog");
|
|
return rss({
|
|
title: SITE_TITLE,
|
|
description: SITE_DESCRIPTION,
|
|
site: context.site ?? SITE_URL,
|
|
items: posts
|
|
.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf())
|
|
.map((post) => ({
|
|
title: post.data.title,
|
|
pubDate: post.data.pubDate,
|
|
description: post.data.description,
|
|
link: `/blog/${post.id}/`,
|
|
})),
|
|
});
|
|
}
|