What is RSS feed?
RSS is short for Really Simple Syndication and RSS is a way to have information delivered to you.An RSS Feed is a standard XML file listing a website’s content in a subscribable format, allowing readers to consume your content in news aggregators and at many more.How to generate RSS feed with gatsby.js
To generate RSS feed with gatsby we will use gatsby-plugin-feed package. To install this package move to your home directory and run the following command.npm install --save gatsby-plugin-feedCustomizing the RSS feed plugin
After complete installation you have to add plugin in your config file under plugins array.The RSS feed needs a way to uniquely identify content, by URL or slug or path. You need to add the plugin in gatsby-config.js file and customize it as per your requirement. Below is a snippet I am using.{
resolve: `gatsby-plugin-feed`,
options: {
query: `
{
site {
siteMetadata {
title
description
siteUrl
site_url: siteUrl
}
}
}
`,
feeds: [
{
serialize: ({ query: { site, allMarkdownRemark } }) => {
return allMarkdownRemark.edges.map(edge => {
return Object.assign({}, edge.node.frontmatter, {
description: edge.node.excerpt,
date: edge.node.frontmatter.date,
url: site.siteMetadata.siteUrl + edge.node.fields.slug,
guid: site.siteMetadata.siteUrl + edge.node.fields.slug,
custom_elements: [{ "content:encoded": edge.node.html }],
})
})
},
query: `
{
allMarkdownRemark(
sort: { order: DESC, fields: [frontmatter___date] },
) {
edges {
node {
excerpt
html
fields { slug }
frontmatter {
title
date
}
}
}
}
}
`,
output: "/rss.xml",
title: "Your Site's RSS Feed",
},
],
}
}gatsby build && gatsby serve

