// rss.xml (RSS 2.0): the latest published changes, to follow or share: new versions of works, new e-books, // arrangements and tags, each with who made it (public names) and, for a work, its opening lines. import type { APIRoute } from 'astro'; import { api } from '../lib/api'; import { brand } from '../lib/brand'; import { siteUrl, xml } from '../lib/site-url'; import { ud } from '../lib/urdu'; const KIND: Record = { work: 'نیا ورژن', ebook: 'نئی ای بک', order: 'نئی ترتیب', tags: 'ٹیگ' }; export const GET: APIRoute = async ({ url }) => { const base = siteUrl(url), items = (await api('/api/feed?limit=50')) ?? []; const item = (i: any) => { const title = `${KIND[i.kind]}: ${i.title}${i.poet ? ` (${i.poet})` : ''}${i.kind === 'work' && i.version ? ` · ورژن ${ud(i.version)}` : ''}`; const text = [i.lines.join(' / '), i.summary, i.by && `از ${i.by}`].filter(Boolean).join(' — '); return `${xml(title)}${xml(base + encodeURI(i.url))}` + `divan-${i.id}${new Date(i.published).toUTCString()}` + `${i.by ? `${xml(i.by)}` : ''}${xml(KIND[i.kind])}${xml(text)}`; }; const body = ` ${xml(`${brand.name}: نئی تبدیلیاں`)} ${xml(base)}/ ${xml(`${brand.name} (${brand.tagline}) میں شائع ہونے والے نئے ورژن، ای بکس اور تبدیلیاں`)} ur-PK ${items.length ? `${new Date(items[0].published).toUTCString()}\n` : ''}${items.map(item).join('\n')} `; return new Response(body, { headers: { 'content-type': 'application/rss+xml; charset=utf-8', 'cache-control': 'public, max-age=300' } }); };