mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-08-03 19:17:07 -04:00
56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import { Feed } from 'feed';
|
|
import marked from 'marked';
|
|
|
|
import { getPosts } from '~/server/blog.ts';
|
|
import { getLocale, loadConfig, loadTranslator } from '~/server/data.ts';
|
|
import { getUrlForLocale } from '~/src/domain.ts';
|
|
import parseMarkdown from '~/src/parseMarkdown.ts';
|
|
|
|
export default defineCachedEventHandler(async (event) => {
|
|
const locale = getLocale(event);
|
|
const [config, translator] = await Promise.all([loadConfig(locale), loadTranslator(locale)]);
|
|
|
|
const baseUrl = getUrlForLocale(locale);
|
|
const posts = await getPosts(config);
|
|
|
|
const feed = new Feed({
|
|
title: `${translator.translate('title')} • ${translator.translate('links.blog')}`,
|
|
description: translator.translate('description'),
|
|
id: baseUrl,
|
|
link: `${baseUrl}/blog.atom`,
|
|
language: config.locale,
|
|
image: `${baseUrl}/icon.png`,
|
|
favicon: `${baseUrl}/icon.png`,
|
|
updated: new Date(posts[0].date),
|
|
copyright: '',
|
|
});
|
|
|
|
for (const post of posts) {
|
|
const markdown = marked(post.content);
|
|
const parsed = await parseMarkdown(markdown, translator);
|
|
|
|
feed.addItem({
|
|
title: post.title,
|
|
id: `${baseUrl}/${config.links.blogRoute}/${post.slug}`,
|
|
link: `${baseUrl}/${config.links.blogRoute}/${post.slug}`,
|
|
description: parsed.intro ?? undefined,
|
|
content: parsed.content ?? undefined,
|
|
author: post.authors.map((author) => ({
|
|
name: author,
|
|
link: author.startsWith('@') ? `${baseUrl}/${author}` : undefined,
|
|
})),
|
|
date: new Date(post.date),
|
|
image: post.hero ? `${baseUrl}${post.hero.src}` : undefined,
|
|
});
|
|
}
|
|
|
|
return new Response(feed.atom1(), {
|
|
headers: {
|
|
'Content-Type': 'application/rss+xml; charset=utf-8',
|
|
},
|
|
});
|
|
}, {
|
|
// TODO key
|
|
maxAge: Infinity,
|
|
});
|