📅  最后修改于: 2023-12-03 15:30:52.852000             🧑  作者: Mango
Gatsby-Plugin-Feed-Generator is a plugin used to automatically generate optimized RSS and Atom feeds for your Gatsby site. With little configuration, this plugin will create feeds for all posts, pages, and other content on your site, allowing readers to subscribe to your content and stay up-to-date.
To install the plugin, simply run the following command in your Gatsby site's directory:
npm install gatsby-plugin-feed-generator --save-dev
To configure the plugin, add it to your gatsby-config.js
file:
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-feed-generator`,
options: {
// options here
}
}
]
}
rss
: (default: true
) Set to false
to disable the generation of RSS feeds.atom
: (default: true
) Set to false
to disable the generation of Atom feeds.query
: (default: graphql
) Set the query name to generate the feed from.feeds
: (default: []
) An array of feed configurations. The output
property is required for each configuration object.query
: A GraphQL query to use for this feed configuration. If not specified, the query
property from above will be used.title
: The title of the feed.output
: The output file name (i.e. rss.xml
).link
: The URL to the site.match
: An optional function to filter posts to be included in this feed.module.exports = {
plugins: [
{
resolve: `gatsby-plugin-feed-generator`,
options: {
rss: true,
atom: true,
query: `
{
allMarkdownRemark(
sort: { order: DESC, fields: [frontmatter___date] },
) {
edges {
node {
excerpt
html
frontmatter {
title
date
}
fields {
slug
}
}
}
}
}
`,
feeds: [
{
title: 'My Blog',
output: '/rss.xml',
link: 'https://www.example.com',
match: node => node.frontmatter.published,
},
],
},
},
],
};
Gatsby-Plugin-Feed-Generator is a great plugin to help your users easily keep up with your content. With little configuration required, this plugin will automatically generate RSS and Atom feeds for your site, making it simple for your readers to subscribe to your content. Give it a try on your Gatsby site today!
### Example Configuration
```js
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-feed-generator`,
options: {
rss: true,
atom: true,
query: `
{
allMarkdownRemark(
sort: { order: DESC, fields: [frontmatter___date] },
) {
edges {
node {
excerpt
html
frontmatter {
title
date
}
fields {
slug
}
}
}
}
}
`,
feeds: [
{
title: 'My Blog',
output: '/rss.xml',
link: 'https://www.example.com',
match: node => node.frontmatter.published,
},
],
},
},
],
};