Files
blog/src/pages/rss.xml.ts
2023-08-22 22:52:01 -04:00

39 lines
882 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import rss from '@astrojs/rss';
import { SITE, METADATA, APP_BLOG } from '~/utils/config';
import { fetchPosts } from '~/utils/blog';
import { getPermalink } from '~/utils/permalinks';
export const GET = async () => {
if (!APP_BLOG.isEnabled) {
return new Response(null, {
status: 404,
statusText: 'Not found',
});
}
const posts = await fetchPosts();
const { body = '' } = await rss({
title: `${SITE.name}s Blog`,
description: METADATA?.description || '',
site: import.meta.env.SITE,
items: posts.map((post) => ({
link: getPermalink(post.permalink, 'post'),
title: post.title,
description: post.excerpt,
pubDate: post.publishDate,
})),
trailingSlash: SITE.trailingSlash,
});
return new Response(body, {
status: 200,
headers: {
'Content-Type': 'application/xml',
},
});
};