Something went wrong. Try again.
doll.systems community website
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344import rss from '@astrojs/rss';import { experimental_AstroContainer as AstroContainer } from 'astro/container';import { render } from 'astro:content';import type { APIRoute } from 'astro';import { catalog, documentHref } from '../lib/content';import { site } from '../lib/site';
const escapeXml = (text: string) => text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
export const GET: APIRoute = async ({ site: origin }) => { const { posts } = await catalog(); const container = await AstroContainer.create(); const items = await Promise.all( posts.map(async (entry) => { const { Content } = await render(entry); const page = new URL(documentHref(entry), origin); const content = (await container.renderToString(Content)).replace( /\b(href|src)="([^"]+)"/g, (_match, attribute: string, value: string) => `${attribute}="${new URL(value.replaceAll('&', '&'), page).href.replaceAll('&', '&')}"`, ); return { title: entry.data.title, description: entry.data.excerpt, pubDate: entry.data.date, customData: entry.authors .map(({ author }) => `<dc:creator>${escapeXml(author.data.name)}</dc:creator>`) .join(''), link: documentHref(entry), content, }; }), ); return rss({ title: site.name, description: `Latest writing from ${site.name}.`, site: origin!, xmlns: { atom: 'http://www.w3.org/2005/Atom', dc: 'http://purl.org/dc/elements/1.1/' }, customData: `<atom:link href="${new URL('/rss.xml', origin)}" rel="self" type="application/rss+xml"/>`, items, });};