// RSS feed of published tutorials, newest first, for feed readers and anything that watches for new posts
import { AUTHOR, SITE_DESCRIPTION, SITE_NAME, SITE_URL } from "@/lib/seo";
import { getTrack } from "@/lib/tracks";
import { getPublishedTutorials } from "@/lib/tutorials";
export const dynamic = "force-static";
const escape = (text: string) =>
text.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """);
const rfc822 = (day: string) => new Date(`${day}T12:00:00Z`).toUTCString();
export function GET() {
const tutorials = getPublishedTutorials();
const items = tutorials
.map((t) => {
const url = `${SITE_URL}/${t.track}/${t.slug}`;
return [
" - ",
` ${escape(t.title)}`,
` ${url}`,
` ${url}`,
` ${escape(t.description)}`,
` ${escape(getTrack(t.track)?.name ?? t.track)}`,
` ${escape(AUTHOR.name)}`,
t.publishedAt ? ` ${rfc822(t.publishedAt)}` : "",
"
",
]
.filter(Boolean)
.join("\n");
})
.join("\n");
const xml = `
${escape(SITE_NAME)}
${SITE_URL}
${escape(SITE_DESCRIPTION)}
en
${tutorials[0]?.publishedAt ? ` ${rfc822(tutorials[0].publishedAt)}\n` : ""}${items}
`;
return new Response(xml, { headers: { "Content-Type": "application/rss+xml; charset=utf-8" } });
}