From c4c5843b23cda95e9aa918e4d3a649d04b06d02e Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Thu, 19 Oct 2023 19:38:57 +0200 Subject: [PATCH] feat: re-add Drupal Planet RSS feed --- src/pages/rss/drupal-planet.xml.js | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/pages/rss/drupal-planet.xml.js diff --git a/src/pages/rss/drupal-planet.xml.js b/src/pages/rss/drupal-planet.xml.js new file mode 100644 index 00000000..7bc3b18c --- /dev/null +++ b/src/pages/rss/drupal-planet.xml.js @@ -0,0 +1,38 @@ +import MarkdownIt from 'markdown-it'; +import _ from 'lodash'; +import rss from '@astrojs/rss'; +import sanitizeHtml from 'sanitize-html'; +import { getCollection } from 'astro:content'; + +export async function get() { + const emails = await getCollection('daily-email'); + + const filteredEmails = Object.values(emails).filter(e => { + return e.data.tags?.includes('drupal'); + }); + + const sortedEmails = filteredEmails + .sort((a, b) => + new Date(b.data.pubDate).valueOf() - + new Date(a.data.pubDate).valueOf() + ); + + const parser = new MarkdownIt(); + + return rss({ + title: 'Daily email list', + description: 'A daily newsletter on software development, DevOps, community, and open-source.', + site: import.meta.env.SITE, + + items: sortedEmails.slice(0, 1).map((email) => ({ + description: ` +
+ ${sanitizeHtml(parser.render(email.body))} +
+ `, + link: `${import.meta.env.SITE}/${email.data.permalink}`, + pubDate: email.data.pubDate, + title: `${email.data.title.trim()}`, + })) + }); +};