summaryrefslogtreecommitdiff
path: root/src/pages/rss.xml.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/pages/rss.xml.ts')
-rw-r--r--src/pages/rss.xml.ts32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/pages/rss.xml.ts b/src/pages/rss.xml.ts
new file mode 100644
index 0000000..c07f3bd
--- /dev/null
+++ b/src/pages/rss.xml.ts
@@ -0,0 +1,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/env.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}/`,
+ };
+ })),
+ });
+};