28
loading...
This website collects cookies to deliver better user experience
Imagine being able to log into one dashboard and getting the latest news and events from all of your favorite websites, blogs, or podcasts? With RSS feeds, it’s possible!
<description>
nor content
of each <item>
in the channel can't have regular HTML in it. The HTML tags must be encoded. Secondly, I found out it's really difficult to try to parse the HTML content in a Node.js environment on my own before putting it into the feed.feed
package.yarn add feed
generateRSSFeed
function.const generateRSSFeed = (articles) => {
const baseUrl = 'https://ashleemboyer.com';
const author = {
name: 'Ashlee Boyer',
email: '[email protected]',
link: 'https://twitter.com/ashleemboyer',
};
// Construct a new Feed object
const feed = new Feed({
title: 'Articles by Ashlee M Boyer',
description:
"You can find me talking about issues surrounding Disability, Accessibility, and Mental Health on Twitter, or you can find me regularly live-knitting or live-coding on Twitch. I'm @AshleeMBoyer on all the platforms I use.",
id: baseUrl,
link: baseUrl,
language: 'en',
feedLinks: {
rss2: `${baseUrl}/rss.xml`,
},
author,
});
// Add each article to the feed
articles.forEach((post) => {
const {
content,
fileName,
meta: { date, description, title },
} = post;
const url = `${baseUrl}/${fileName}`;
feed.addItem({
title,
id: url,
link: url,
description,
content,
author: [author],
date: new Date(date),
});
});
// Write the RSS output to a public file, making it
// accessible at ashleemboyer.com/rss.xml
fs.writeFileSync('public/rss.xml', feed.rss2());
};
getStaticProps
function exported from src/pages/index.jsx
to call the new generateRSSFeed
function.export async function getStaticProps() {
const articles = getAllArticles();
articles.sort((a, b) => (a.meta.date < b.meta.date ? 1 : -1)
generateRSSFeed(articles);
return { props: { articles } };
}
getStaticProps
will be called at that time and so will generateRSSFeed
. This means the feed is always up to date when I push a new Markdown file for each post or whenever existing files are updated.