import { fetchPostsSorted, resolveBlogPath } from "$src/lib/util/Blogs"; export const prerender = true; const feedUpdated = new Date(); function escapeXml(unsafe: string): string { return unsafe .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); } function makeThumbnail(post: App.BlogPost): string { if (!post.thumbnail) return ''; const alt = !!post.thumbnailAlt ? ` alt="${escapeXml(post.thumbnailAlt)}"` : ''; return `

`; } function makeAuthors(post: App.BlogPost): string { const authors = (post.authors == null ? [] : typeof post.authors === 'string' ? [post.authors] : post.authors) .map(a => escapeXml(a)); if (authors.length === 0) return ''; let authorsString = authors[0]; if (authors.length > 1) { const lastAuthor = authors.pop(); authorsString = `${authors.join(', ')} и ${lastAuthor}`; } return `\n${authorsString}`; } export async function GET({ setHeaders }) { setHeaders({ 'Cache-Control': 'max-age=0, s-maxage=3600', 'Content-Type': 'application/rss+xml', }); const posts = await fetchPostsSorted(); return new Response(String(` Блог Tea Sanctuary Лента с новостями, заметками и событиями Tea Sanctuary https://teasanctuary.ru/blog 1800 ${posts.map((post) => ` ${escapeXml(post.title)} ${makeAuthors(post)} https://teasanctuary.ru/blog/${post.slug} https://teasanctuary.ru/blog/${post.slug} ${(new Date(post.date!)).toUTCString()} `).join("\n")} `)) }