1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
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<Response> => {
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<RSSFeedItem> => {
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}/`,
};
})),
});
};
|