Build A Static RSS Reader To Fight Your Inner FOMO<\/h1>\nKarin Hendrikse<\/address>\n 2024-10-07T13:00:00+00:00
\n 2024-10-15T23:05:45+00:00
\n <\/header>\n
In a fast-paced industry like tech, it can be hard to deal with the fear of missing out on important news. But, as many of us know, there\u2019s an absolutely huge amount of information coming in daily, and finding the right time and balance to keep up can be difficult, if not stressful. A classic piece of technology like an RSS feed is a delightful way of taking back ownership of our own time<\/strong>. In this article, we will create a static Really Simple Syndication (RSS) reader that will bring you the latest curated news only once (yes: once<\/em>) a day.<\/p>\nWe\u2019ll obviously work with RSS technology in the process, but we\u2019re also going to combine it with some things that maybe you haven\u2019t tried before, including Astro<\/strong> (the static site framework), TypeScript<\/strong> (for JavaScript goodies), a package called rss-parser<\/strong> (for connecting things together), as well as scheduled functions<\/strong> and build hooks<\/strong> provided by Netlify (although there are other services that do this).<\/p>\nI chose these technologies purely because I really, really enjoy them! There may be other solutions out there that are more performant, come with more features, or are simply more comfortable to you — and in those cases, I encourage you to swap in whatever you\u2019d like. The most important thing is getting the end result!<\/p>\n
The Plan<\/h2>\n
Here\u2019s how this will go. Astro generates the website. I made the intentional decision to use a static site because I want the different RSS feeds to be fetched only once during build time, and that\u2019s something we can control each time the site is \u201crebuilt\u201d and redeployed with updates. That\u2019s where Netlify\u2019s scheduled functions come into play, as they let us trigger rebuilds automatically at specific times. There is no need to manually check for updates and deploy them! Cron jobs can just as readily do this if you prefer a server-side solution.<\/p>\n
During the triggered rebuild, we\u2019ll let the rss-parser package do exactly what it says it does: parse a list of RSS feeds that are contained in an array. The package also allows us to set a filter for the fetched results so that we only get ones from the past day, week, and so on. Personally, I only render the news from the last seven days to prevent content overload. We\u2019ll get there!<\/p>\n
But first…<\/p>\n
What Is RSS?<\/h2>\n
RSS is a web feed technology that you can feed into a reader or news aggregator. Because RSS is standardized, you know what to expect when it comes to the feed\u2019s format. That means we have a ton of fun possibilities when it comes to handling the data that the feed provides. Most news websites have their own RSS feed that you can subscribe to (this is Smashing Magazine\u2019s RSS feed<\/strong>: https:\/\/www.smashingmagazine.com\/feed\/<\/a>). An RSS feed is capable of updating every time a site publishes new content, which means it can be a quick source of the latest news, but we can tailor that frequency as well.<\/p>\nRSS feeds are written in an Extensible Markup Language (XML) format and have specific elements that can be used within it. Instead of focusing too much on the technicalities here, I\u2019ll give you a link to the RSS specification<\/a>. Don\u2019t worry; that page should be scannable enough for you to find the most pertinent information you need, like the kinds of elements that are supported and what they represent. For this tutorial, we\u2019re only using the following elements: <title><\/code><\/strong>, <link><\/code><\/strong>, <description><\/code><\/strong>, <item><\/code><\/strong>, and <pubDate><\/code><\/strong>. We\u2019ll also let our RSS parser package do some of the work for us.<\/p>\n\n
\n 2024-10-15T23:05:45+00:00
\n <\/header>\n
We\u2019ll obviously work with RSS technology in the process, but we\u2019re also going to combine it with some things that maybe you haven\u2019t tried before, including Astro<\/strong> (the static site framework), TypeScript<\/strong> (for JavaScript goodies), a package called rss-parser<\/strong> (for connecting things together), as well as scheduled functions<\/strong> and build hooks<\/strong> provided by Netlify (although there are other services that do this).<\/p>\n I chose these technologies purely because I really, really enjoy them! There may be other solutions out there that are more performant, come with more features, or are simply more comfortable to you — and in those cases, I encourage you to swap in whatever you\u2019d like. The most important thing is getting the end result!<\/p>\n Here\u2019s how this will go. Astro generates the website. I made the intentional decision to use a static site because I want the different RSS feeds to be fetched only once during build time, and that\u2019s something we can control each time the site is \u201crebuilt\u201d and redeployed with updates. That\u2019s where Netlify\u2019s scheduled functions come into play, as they let us trigger rebuilds automatically at specific times. There is no need to manually check for updates and deploy them! Cron jobs can just as readily do this if you prefer a server-side solution.<\/p>\n During the triggered rebuild, we\u2019ll let the rss-parser package do exactly what it says it does: parse a list of RSS feeds that are contained in an array. The package also allows us to set a filter for the fetched results so that we only get ones from the past day, week, and so on. Personally, I only render the news from the last seven days to prevent content overload. We\u2019ll get there!<\/p>\n But first…<\/p>\n RSS is a web feed technology that you can feed into a reader or news aggregator. Because RSS is standardized, you know what to expect when it comes to the feed\u2019s format. That means we have a ton of fun possibilities when it comes to handling the data that the feed provides. Most news websites have their own RSS feed that you can subscribe to (this is Smashing Magazine\u2019s RSS feed<\/strong>: https:\/\/www.smashingmagazine.com\/feed\/<\/a>). An RSS feed is capable of updating every time a site publishes new content, which means it can be a quick source of the latest news, but we can tailor that frequency as well.<\/p>\n RSS feeds are written in an Extensible Markup Language (XML) format and have specific elements that can be used within it. Instead of focusing too much on the technicalities here, I\u2019ll give you a link to the RSS specification<\/a>. Don\u2019t worry; that page should be scannable enough for you to find the most pertinent information you need, like the kinds of elements that are supported and what they represent. For this tutorial, we\u2019re only using the following elements: The Plan<\/h2>\n
What Is RSS?<\/h2>\n
<title><\/code><\/strong>,
<link><\/code><\/strong>,
<description><\/code><\/strong>,
<item><\/code><\/strong>, and
<pubDate><\/code><\/strong>. We\u2019ll also let our RSS parser package do some of the work for us.<\/p>\n