From 6972d357c69495b6e1beee75e8441815bd3d5c72 Mon Sep 17 00:00:00 2001 From: Joe Carstairs <65492573+Sycamost@users.noreply.github.com> Date: Fri, 25 Aug 2023 18:14:08 +0100 Subject: Adds Lallans to RSS feed --- src/pages/[locale]/rss.xml.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/pages') diff --git a/src/pages/[locale]/rss.xml.ts b/src/pages/[locale]/rss.xml.ts index be2cab6..0feb866 100644 --- a/src/pages/[locale]/rss.xml.ts +++ b/src/pages/[locale]/rss.xml.ts @@ -6,21 +6,26 @@ import getLocaleFromPath from '$lib/getLocaleFromPath'; import type { APIContext } from 'astro'; import translate from '$i18n/translate'; import tFeed from '$i18n/translations/pages/rss.xml'; +import type LallansIssue from '$types/LallansIssue'; +import type Locale from '$types/Locale'; +import { getAllLallansIssues } from '$data/lallans'; export async function get(context: APIContext) { const locale = getLocaleFromPath(context.url.pathname); const t = translate(locale); - const news = (await getCollection('news')).filter((item) => isNewsItemInLocale(item, locale)); const site = context.site; if (!site) { throw new Error('No site provided in Astro configuration'); } + const news = (await getCollection('news')).filter((item) => isNewsItemInLocale(item, locale)); + const lallans = await getAllLallansIssues(); + return rss({ title: t(tFeed, { key: 'title' }), description: t(tFeed, { key: 'description' }), site, - items: news.map(newsItemToRssFeedItem), + items: [...news.map(newsItemToRssFeedItem), ...lallans.map(lallansIssueToRssFeedItem(locale))], customData: `${locale}`, }); } @@ -39,6 +44,17 @@ function newsItemToRssFeedItem(item: CollectionEntry<'news'>): RSSFeedItem { }; } +function lallansIssueToRssFeedItem(locale: Locale) { + return function (issue: LallansIssue): RSSFeedItem { + return { + link: `/${locale}/furthsettins/lallans/${issue.issueNumber}`, + title: issue.issueName, + description: issue.description[locale], + pubDate: new Date(issue.uploadDate), + }; + }; +} + export async function getStaticPaths() { return localeStaticPaths; } -- cgit v1.2.3