import type { APIRoute } from 'astro'; import { isPublishable } from '../lib'; import { getCollection } from 'astro:content'; import authors from '../data/authors.json'; export const GET: APIRoute = async ({ site }) => { const base = site!.toString().replace(/\/$/, ''); const posts = (await getCollection('posts')).filter(isPublishable); const today = new Date().toISOString().slice(0, 10); const urls = [ { loc: `${base}/`, lastmod: today }, { loc: `${base}/posts`, lastmod: today }, { loc: `${base}/clinic`, lastmod: today }, { loc: `${base}/visit`, lastmod: today }, { loc: `${base}/plan`, lastmod: today }, { loc: `${base}/en/plan`, lastmod: today }, { loc: `${base}/newsroom`, lastmod: today }, { loc: `${base}/videos`, lastmod: today }, { loc: `${base}/about`, lastmod: today }, { loc: `${base}/corrections`, lastmod: today }, ...Object.keys(authors.supporters).map((id) => ({ loc: `${base}/authors/${id}`, lastmod: today })), ...posts.map((p) => ({ loc: `${base}/posts/${p.id}`, lastmod: p.data.dateModified })), ]; const xml = `\n\n${urls.map((u) => ` ${u.loc}${u.lastmod}`).join('\n')}\n\n`; return new Response(xml, { headers: { 'Content-Type': 'application/xml; charset=utf-8' } }); };