📌  相关文章
📜  gatsby-plugin-feed-generator - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:30:52.852000             🧑  作者: Mango

Gatsby-Plugin-Feed-Generator (Shell-Bash)

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.

Installation

To install the plugin, simply run the following command in your Gatsby site's directory:

npm install gatsby-plugin-feed-generator --save-dev
Configuration

To configure the plugin, add it to your gatsby-config.js file:

module.exports = {
  plugins: [
    {
      resolve: `gatsby-plugin-feed-generator`,
      options: {
        // options here
      }
    }
  ]
}
Options
  1. rss: (default: true) Set to false to disable the generation of RSS feeds.
  2. atom: (default: true) Set to false to disable the generation of Atom feeds.
  3. query: (default: graphql) Set the query name to generate the feed from.
  4. 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.
Example Configuration
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,
          },
        ],
      },
    },
  ],
};
Conclusion

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,
          },
        ],
      },
    },
  ],
};