main
 1import { getCollection } from "astro:content";
 2import type { APIRoute } from "astro";
 3
 4import { DEFAULT_LOCALE, SITE_CONFIG } from "@/config.ts";
 5import { createFeed, localePostUrl } from "@/utils/feed.ts";
 6import { url } from "@/utils/url.ts";
 7
 8export const GET: APIRoute = async ({ site }) => {
 9  if (!site) {
10    throw new Error("`site` must be configured in astro.config to build feeds");
11  }
12  const origin = site.origin;
13  const feed = await createFeed({
14    id: new URL(url("/"), origin).toString(),
15    feedUrl: new URL(url("/feed.atom"), origin).toString(),
16    favicon: new URL(url("/favicon.ico"), origin).toString(),
17    title: SITE_CONFIG.title,
18    description: SITE_CONFIG.description[DEFAULT_LOCALE],
19    language: DEFAULT_LOCALE,
20    site: origin,
21    posts: await getCollection("posts"),
22    postUrl: (post) => localePostUrl(post, origin),
23  });
24
25  return new Response(feed.atom1(), {
26    headers: { "Content-Type": "application/atom+xml" },
27  });
28};