You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(gatsby-transformer-remark): Allow for multiple different remark sources (#7512)
<!--
Q. Which branch should I use for my pull request?
A. Use `master` branch (probably).
Q. Which branch if my change is an update to Gatsby v2?
A. Definitely use `master` branch :)
Q. Which branch if my change is an update to documentation or gatsbyjs.org?
A. Use `master` branch. A Gatsby maintainer will copy your changes over to the `v1` branch for you
Q. Which branch if my change is a bug fix for Gatsby v1?
A. In this case, you should use the `v1` branch
Q. Which branch if I'm still not sure?
A. Use `master` branch. Ask in the PR if you're not sure and a Gatsby maintainer will be happy to help :)
Note: We will only accept bug fixes for Gatsby v1. New features should be added to Gatsby v2.
Learn more about contributing: https://www.gatsbyjs.org/docs/how-to-contribute/
-->
This PR allows for having more than one gatsby-transformer-remark plugin. With the addition of the `filter` option, the user can now decide which nodes should be handled by which plugin. For instance, with gatsby-source-filesystem, one could do the following in order to have multiple different markdown sources:
```js
const plugins = [
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/src/pages`,
name: `pages`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/src/blog`,
name: `blog`,
},
},
{
resolve: `gatsby-transformer-remark`,
options: {
filter: node => node.sourceInstanceName === `pages`,
type: `MarkdownPage`,
},
},
{
resolve: `gatsby-transformer-remark`,
options: {
filter: node => node.sourceInstanceName === `blog`,
type: `BlogPost`,
},
}
]
```
I've also added a `type` option so that these different plugins create GraphQL types with different names.
In the above example, we could expect that our markdown pages might have different frontmatter fields than our blog entries, but having them all under the `MarkdownRemark` type would force us to add filters on fields in order to only retrieve a list of either of them. Having different frontmatter formats would also pollute our GraphiQL documentation.
Co-authored-by: Ward Peeters <ward@coding-tech.com>
0 commit comments