The internals for gatsby-plugin-feed seem to indicate that we can set a limit on the number of posts that show up in the feed:
{
// Create a default RSS feed. Others may be added by using the format below.
feeds: [
{
query: `
{
allMarkdownRemark(
limit: 1000,
sort: {
order: DESC,
fields: [frontmatter___date]
}
) {
edges {
node {
frontmatter {
title
date
}
fields {
slug
}
excerpt
html
}
}
}
}
`,
...
]
}
When I try to change limit
to 10
in my own definition within gatsby-config.js
, it seems to have no effect. Is there a standard way to limit the number of items in the RSS feed so that I don't have 250+ posts in there?
@AlbertSkibinski's documentation link in his comment helped me to realize that the RSS feed is only generated on gatsby build
. I was making changes and trying to run gatsby develop
, which had no effect on the output that I was examining in the public
folder.
I am not a huge fan of overwriting default values that don't need to be overridden, so I pieced together my own config code by importing the defaults from gatsby-plugin-feed/internals
:
const gatsbyFeedOpts = require('gatsby-plugin-feed/internals')
// Copy and replace limit in default options
let feedOpts = gatsbyFeedOpts.defaultOptions
feedOpts.feeds[0].query = feedOpts.feeds[0].query.replace(
'limit: 1000',
'limit: 10'
)
module.exports = {
siteMetadata: {
// Excluded for brevity
},
plugins: [
// Other plugins excluded for brevity
{
resolve: `gatsby-plugin-feed`,
options: feedOpts,
},
],
}
It's interesting to note that even though the documentation says we need to implement a serialize
method within the feed config, it wasn't included in the imported defaults that I'm using here. This could cause problems in future versions of gatsby-plugin-feed
, but it works fine with the version I'm currently using (2.4.1).