Set up initial project and files

This commit is contained in:
Young Lee
2025-02-27 14:51:38 -08:00
parent be9d1c0f61
commit 8839aac24b
18 changed files with 1754 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
import { Feed } from 'feed';
import { FeedConfig, EmailData } from '../types';
/**
* Generate an RSS feed from a list of emails
*/
export function generateRssFeed(
feedConfig: FeedConfig,
emails: EmailData[],
baseUrl: string
): string {
// Create a new feed
const feed = new Feed({
title: feedConfig.title,
description: feedConfig.description || '',
id: feedConfig.feed_url,
link: feedConfig.site_url,
language: feedConfig.language,
updated: new Date(),
generator: 'Email-to-RSS',
copyright: `Copyright © ${new Date().getFullYear()} ${feedConfig.title}`,
feedLinks: {
rss: feedConfig.feed_url
},
author: feedConfig.author ? {
name: feedConfig.author,
email: `noreply@${new URL(feedConfig.site_url).hostname}`
} : undefined
});
// Add each email as a feed item
for (const email of emails) {
const date = new Date(email.receivedAt);
const uniqueId = `${email.receivedAt}-${Buffer.from(email.subject).toString('base64').substring(0, 10)}`;
feed.addItem({
title: email.subject,
id: uniqueId,
link: `${baseUrl}/emails/${uniqueId}`,
description: email.content,
content: email.content,
author: [
{
name: email.from,
},
],
date: date,
});
}
// Return the RSS feed as XML
return feed.rss2();
}