2023-04-09 11:25:12 +01:00
|
|
|
import MarkdownIt from 'markdown-it';
|
2022-10-07 09:14:10 +01:00
|
|
|
import rss from '@astrojs/rss';
|
2023-04-09 11:25:12 +01:00
|
|
|
import sanitizeHtml from 'sanitize-html';
|
|
|
|
import { getCollection } from 'astro:content';
|
2022-10-07 09:14:10 +01:00
|
|
|
|
2023-04-09 11:25:12 +01:00
|
|
|
export async function get() {
|
|
|
|
const emails = await getCollection('daily-email');
|
2022-10-13 00:15:24 +01:00
|
|
|
|
2023-04-09 11:25:12 +01:00
|
|
|
const sortedEmails = Object.values(emails)
|
|
|
|
.sort((a, b) =>
|
|
|
|
new Date(b.data.pubDate).valueOf() -
|
|
|
|
new Date(a.data.pubDate).valueOf()
|
|
|
|
);
|
|
|
|
|
|
|
|
const parser = new MarkdownIt();
|
|
|
|
|
|
|
|
return rss({
|
2022-10-13 08:40:06 +01:00
|
|
|
title: 'Daily email list',
|
2022-10-13 00:15:24 +01:00
|
|
|
description: 'A daily newsletter on software development, DevOps, community, and open-source.',
|
|
|
|
site: import.meta.env.SITE,
|
2023-04-09 11:25:12 +01:00
|
|
|
|
|
|
|
items: sortedEmails.slice(0, 1).map((email) => ({
|
|
|
|
description: `<div style="max-width: 550px;">${sanitizeHtml(parser.render(email.body))}</div>`,
|
|
|
|
link: `${import.meta.env.SITE}/${email.data.permalink}`,
|
|
|
|
pubDate: email.data.pubDate,
|
2023-04-11 14:00:30 +01:00
|
|
|
title: `${email.data.title} ${email.data.tags.map(tag => `#${tag}`).join(' ')}`,
|
2022-10-13 00:15:24 +01:00
|
|
|
}))
|
|
|
|
});
|
2023-04-09 11:25:12 +01:00
|
|
|
};
|