-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(gatsby-transformer-remark): Allow for multiple different remark sources #7512
feat(gatsby-transformer-remark): Allow for multiple different remark sources #7512
Conversation
It could make sense to adopt this kind of API for other transformers as well. |
Deploy preview for using-contentful failed. Built with commit 59aadf5 https://app.netlify.com/sites/using-contentful/deploys/5b82917d4ed62f7116e8d176 |
fc4ca3e
to
2116fff
Compare
Thanks @alexkirsz 👍 this is a really useful feature - so much so, that something like it should be added to Gatsby core instead of this being implemented separately across different plugins. It'll be particularly useful for the new Gatsby themes functionality that @ChristopherBiscardi is working on. As part of the themes work there's going to be an issue or rfc soon™️ (next week or after) to figure out exactly how this could be added to Gatsby core. Once the rfc has been written I'll add a link here. |
@m-allanson Any news on this? I'm not quite sure how this would play with other transformers. For instance, the yaml transformer already leverages folder names and/or file names to generate types. |
59aadf5
to
57ec6dd
Compare
57ec6dd
to
c42671b
Compare
FWIW I've rebased on master and published this plugin as @alexkirsz/[email protected] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed bluebird and did some tests and seems to work. Nothing breaks so lets ship this!
thank you for your patience 🙏! 💪
Great! Thanks! |
// Use Bluebird's Promise function "each" to run remark plugins serially. | ||
await Promise.each(pluginOptions.plugins, plugin => { | ||
|
||
await eachPromise(plugins, plugin => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't seem to work
const eachPromise = (input, iterator) => | ||
input.reduce( | ||
(accumulatorPromise, nextValue) => | ||
accumulatorPromise.then(() => void iterator(nextValue)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this void
here is problematic? after removing it, it seems to work - why is it here? some context is needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also generally - where do we stand on this? We use bluebird pretty heavily--so I'm not sure it was worth refactoring this.
But a bit tangential, if we went that way--just need to ensure we have a working alternative for sequential promises!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally don't agree with removing dependency for the sake of removing it (at least for stuff that is only used during the builds and don't end up in production js bundles produced by webpack). If it fixes bugs or improve performance, then that's fine.
I will open PR fixing that and add some tests for this helper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When utils like bluebird
have maintainers with domain knowledge and it was battle-tested by thousands of developers - I will trust that more than hand rolled and not very tested approaches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In any case - here's hot-fix for issue #12578 (first commit on purpose just added failing test, and second commit "fixes" the problem.
@alexkirsz I would appreciate you taking a look on this, because I imagine there was some reason for that void
to be there, but I have no clue what that would be (and it did break that utility)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ok - sorry @alexkirsz. I should pay more attention to individual commits in the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bady, sorry about this
…sources (#12639) ## Description This change should happen in core and not in remark itself. I didn't think this through. I should have read @m-allanson more carefully: > Thanks @alexkirsz 👍 this is a really useful feature - so much so, that something like it should be added to Gatsby core instead of this being implemented separately across different plugins. > It'll be particularly useful for the new Gatsby themes functionality that @ChristopherBiscardi is working on. As part of the themes work there's going to be an issue or rfc soon™️ (next week or after) to figure out exactly how this could be added to Gatsby core. Once the rfc has been written I'll add a link here. > You can check out more info on Gatsby themes here and here. ## Related Issues #7512
hey @alexkirsz I'm sorry but reverted this change (#12639) as @m-allanson was right and we should have this implementation in core.
We want you to know that we certainly want to keep you as a contributor to Gatsby, so we'd encourage you to check out our open issues. Thanks again, and we look forward to seeing more PRs from you in the future! 💪 💜 |
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: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.