From 79fd506d30eef3d113f4a8e3ab9ebd9004f1e8cc Mon Sep 17 00:00:00 2001 From: João Augusto Costa Branco Marado Torres Date: Sat, 28 Jun 2025 18:14:22 -0300 Subject: feat: index page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Augusto Costa Branco Marado Torres --- src/pages/rss.xml.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/pages/rss.xml.ts (limited to 'src/pages/rss.xml.ts') 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 => { + 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}/`, + }; + })), + }); +}; -- cgit v1.2.3