RSS feeds are a way for others to consume your content in their own feed without having to go to your website every time you publish a piece.
Astro gives you a package @astrojs/rss
that helps you create such a feed. On the Astro side, this will be an API route which we haven't touched on yet in this course but just know this is a route that others can hit to give them data, in this case a feed of all your posts.
Here we'll export a GET function that will return an RSS feed. RSS feeds require a certain shape to their data which is what we will provide the function. We'll give it a title, description, site, and items.
The items we'll grab from a call to getCollection
and each will have a title, description, publication date, link, and content. For the content, we are rendering the full post as html. To do this safely we will need to packages: markdown-it
, and sanitize-html
. markdown-it
will take our markdown and produce html and sanitize-html
will strip out any unnecessary HTML.