import { DateTime } from "luxon"; import fetchSyndication from '@utils/data/syndication.js'; import { fetchGlobals } from '@utils/data/globals.js'; import { dateToRFC822, encodeAmp, md } from '@utils/helpers/general.js'; const generateSyndicationRSS = async (globals, entries) => { if (!entries.length) throw new Error('No feed entries found.'); const title = globals.site_name || 'Syndicated Content Feed'; const permalink = '/feeds/syndication.xml'; const xml = ` <![CDATA[${title}]]> ${globals.url} ${dateToRFC822(DateTime.now())} <![CDATA[${title}]]> ${globals.url} ${globals.cdn_url}${globals.avatar}?class=w200 144 144 ${entries .slice(0, 20) .map( (entry) => ` <![CDATA[${entry.syndication.title || 'Untitled'}]]> ${encodeAmp(entry.syndication.url)} ${dateToRFC822(entry.syndication.date)} ${encodeAmp(entry.syndication.url)} ` ) .join('')} `; return xml; }; export async function GET() { try { const [globals, entries] = await Promise.all([ fetchGlobals(), fetchSyndication(), ]); const rss = await generateSyndicationRSS(globals, entries); return new Response(rss, { status: 200, headers: { 'Content-Type': 'application/rss+xml' }, }); } catch (error) { console.error('Error generating syndication feed:', error); return new Response('Error generating syndication feed.', { status: 500 }); } }