Skip to content

Commit

Permalink
feat: refine rss setup (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundhung authored Nov 21, 2022
1 parent e4d5fe8 commit a3c354e
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions app/routes/[rss.xml].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { search } from '~/resources';

interface FeedEntry {
title: string;
description: string | null | undefined;
pubDate: string;
link: string;
guid: string;
}

Expand All @@ -15,13 +15,18 @@ export async function loader({ context }: LoaderArgs) {
limit: 25,
sort: 'new',
});
const entries = list.entries.reduce<FeedEntry[]>((list, resource) => {
if (resource.title) {
list.push({
title: resource.title,
pubDate: new Date(resource.createdAt).toUTCString(),
link: resource.url,
guid: `${domain}/resources/${resource.id}`,
});
}

const entries = list.entries.map<FeedEntry>((resource) => ({
title: resource.title ?? '',
description: resource.description,
pubDate: new Date(resource.createdAt).toUTCString(),
guid: `${domain}/resources/${resource.id}`,
}));
return list;
}, []);

const rss = `
<?xml version="1.0" encoding="utf-8"?>
Expand All @@ -39,8 +44,8 @@ export async function loader({ context }: LoaderArgs) {
`
<item>
<title><![CDATA[${entry.title}]]></title>
<description><![CDATA[${entry.description}]]></description>
<pubDate>${entry.pubDate}</pubDate>
<link>${entry.link}</link>
<guid>${entry.guid}</guid>
</item>
`.trim(),
Expand Down

0 comments on commit a3c354e

Please sign in to comment.