Skip to content

Commit

Permalink
Merge pull request #65 from thegalactiks/add-rss-support
Browse files Browse the repository at this point in the history
Add rss support
  • Loading branch information
emmanuelgautier authored Feb 9, 2024
2 parents caa459f + 03e25b2 commit 4d26a2f
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 29 deletions.
2 changes: 2 additions & 0 deletions packages/adapters/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"peerDependencies": {
"@astrojs/partytown": "2.0.4",
"@astrojs/react": "3.0.10",
"@astrojs/rss": "4.0.5",
"@astrojs/sitemap": "3.0.5",
"astro": "4.3.5",
"astro-critters": "2.0.11",
Expand All @@ -57,6 +58,7 @@
"devDependencies": {
"@astrojs/partytown": "2.0.4",
"@astrojs/react": "3.0.10",
"@astrojs/rss": "4.0.5",
"@astrojs/sitemap": "3.0.5",
"@types/debug": "4.1.12",
"@types/react": "18.2.55",
Expand Down
1 change: 1 addition & 0 deletions packages/adapters/astro/src/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { join } from 'path';
export { getI18nConfig } from './i18n.mjs';
export { getStaticPaths, getIndexPage } from './pages.mjs';
export { integrationsPreset } from './preset.mjs';
export { getRSS } from './rss.mjs';

type GalactiksOptions = {
content?: {
Expand Down
31 changes: 31 additions & 0 deletions packages/adapters/astro/src/rss.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

import rss, { type RSSFeedItem } from '@astrojs/rss';
import { getConfig } from '@galactiks/config';
import { getWebPageDocumentsByType } from '@galactiks/explorer';
import type { APIContext } from 'astro';
import Debug from 'debug';

const debug = Debug('@galactiks/astro-integration:rss');

export async function getRSS(context: APIContext) {
const config = getConfig();
const articles = await getWebPageDocumentsByType('Article');

const items: RSSFeedItem[] = articles.map(item => {
debug('generating rss item', item);

return {
title: item.name,
description: item.description,
link: item.url,
pubDate: item.datePublished,
};
});

return rss({
title: config.webManifest.name,
description: config.webManifest.description,
site: context.site ? context.site.toString() : '',
items,
});
}
104 changes: 75 additions & 29 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4d26a2f

Please sign in to comment.