mottox2 / gatsby-source-rss-feed

Gatsby source plugin for rss feed.
https://www.npmjs.com/package/gatsby-source-rss-feed
24 stars 6 forks source link
gatsby-plugin gatsby-source-plugin gatsbyjs

gatsby-source-rss-feed

npm version

Source plugin for pulling data into Gatsby from RSS feed.

Install

npm install --save gatsby-source-rss-feed

or

yarn add gatsby-source-rss-feed

How to use

basic pattern

// In your gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: `gatsby-source-rss-feed`,
      options: {
        url: `http://static.userland.com/gems/backend/rssTwoExample2.xml`,
        name: `ExampleRSS`,
      }
    }
  ]
}

use multiple feed

// In your gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: `gatsby-source-rss-feed`,
      options: {
        url: `http://static.userland.com/gems/backend/rssTwoExample2.xml`,
        name: `ExampleRSS`,
      }
    }
    {
      resolve: `gatsby-source-rss-feed`,
      options: {
        url: `http://static.userland.com/gems/backend/rssTwoExample2.xml`,
        name: `MyBlog`,
      }
    }
  ]
}

with parserOption

This library use rss-parser.

You can pass options via parserOptions.

// In your gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: `gatsby-source-rss-feed`,
      options: {
        url: `http://static.userland.com/gems/backend/rssTwoExample2.xml`,
        name: `ExampleRSS`,
        // Optional
        // Read parser document: https://github.com/bobby-brennan/rss-parser#readme
        parserOption: {
          customFields: {
            item: ['itunes:duration']
          }
        }
      }
    }
  ]
}

How to query

Query is Feed${name}.

When name of options is ExampleRSS, query named as FeedExampleRSS.

{
  allFeedExampleRSS {
    edges {
      node {
        title
        link
        content
      }
    }
  }

  feedExampleRSS {
    title
    link
    content
  }
}

Data not part of the items can be accessed with Feed${name}Meta

When name of options is ExampleRSS, query named as FeedExampleRSSMeta.

{
  feedExampleRSSMeta {
    title
    author
    description
    lastBuiltDate
  }
}