import rss, { type RSSFeedItem } from "@astrojs/rss"; import { getCollection } from "astro:content"; import type { APIContext, APIRoute } from "astro"; import { Blog } from "../lib/collection/schemas.ts"; import { getFirstAuthorEmail } from "../lib/collection/helpers.ts"; import { env } from "../lib/environment.ts"; const { PUBLIC_SITE_TITLE, PUBLIC_SITE_DESCRIPTION, PUBLIC_SITE_URL } = env; export const GET: APIRoute = async (context: APIContext): Promise => { const posts = await getCollection("blog"); return rss({ title: PUBLIC_SITE_TITLE, description: PUBLIC_SITE_DESCRIPTION, site: context.site ?? PUBLIC_SITE_URL, items: await Promise.all(posts.map(async (post): Promise => { const { id, rendered } = post; const blog = Blog.parse(post.data); const { title, dateUpdated, dateCreated } = blog; return { description: "description" in blog ? blog.description : undefined, title, author: await getFirstAuthorEmail(post), content: rendered?.html, pubDate: dateUpdated ?? dateCreated, categories: "keywords" in blog ? blog.keywords : undefined, link: `/blog/read/${id}/`, }; })), }); };