// RSS 2.0 feed — hand-rolled static endpoint like search.json.js (no @astrojs/rss // dependency; the spec is 20 lines of XML). Newest 30 items, absolute URLs from // the configured `site`. import { getCollection } from 'astro:content'; const esc = (s = '') => s.replace(/[<>&'"]/g, (c) => ({ '<': '<', '>': '>', '&': '&', "'": ''', '"': '"' })[c]); export async function GET(context) { const site = context.site; // always set in astro.config.mjs const posts = (await getCollection('news', ({ data }) => !data.draft)) .sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf()) .slice(0, 30); const items = posts .map((p) => { const url = new URL(`/news/${p.id}`, site).href; return ` ${esc(p.data.title)} ${url} ${url} ${p.data.date.toUTCString()} ${esc(p.data.description)} ${esc(p.data.category)} `; }) .join('\n'); const xml = ` CTAO Science Portal News ${new URL('/news', site).href} News and announcements of the Cherenkov Telescope Array Observatory en ${(posts[0]?.data.date ?? new Date()).toUTCString()} ${items} `; return new Response(xml, { headers: { 'Content-Type': 'application/rss+xml; charset=utf-8' } }); }