Add an RSS Feed to your Gatsby MDX blogUpdated: August 9, 2020
An RSS Feed is a standard XML file with the purpose of listing the content of a website in a subscribable format. It allows readers to consume your content in news aggregators, like a feed reader app. You can think of it like a newsfeed where the content is displayed in a chronological order, without any algorithm choosing the "right" post that will make you click.
To generate an RSS Feed for your Gatsby MDX blog, you need the gatsby-plugin-feed-mdx package. To install this package, run the following command:
Now, it's time to config the
gatsby-plugin-feed-mdx plugin in your
We can have a closer look at all this block of code by examining each option individually.
query attribute allows us to query for site metadata:
query attribute is followed by a
feeds array, that we can use to create multiple feeds.
This can be usefull if you want to generate different feeds for different content types like: blog, courses, podcast or talks. Every content type will be represented by a
Since we are working with an MDX Blog, we need to transform our MDX pages into HTML objects that can be read by RSS Feed readers. For this purpose, we need to use a
feed object will contain also a GraphQL query that will retrieve all our blog posts and sort them in descending order, before filtering out those which are just drafts:
Finally, we need to specify our RSS Feed URL together with a title using the
To see the final output, you can run the following command in your terminal: