Currently, gatsby-transformer-remark adds several fields using setFieldsOnGraphQLNodeType. If these fields do not take any args, it would be better to add them using onCreateNode in order to make them available to other plugins.
In particular, the fields that could (should?) be moved are:
htmlhtmlAsttableOfContentswordCountThe following, untested, pseudo-code should give you the gist.
// hello.md
# Hello World
// gatsby-node.js
exports.onCreateNode = ({ node }) => {
if(node.internal.type === 'MarkdownRemark') {
console.log(node.html) // undefined
}
}
// hello.md
# Hello World
// gatsby-node.js
exports.onCreateNode = ({ node }) => {
if(node.internal.type === 'MarkdownRemark') {
console.log(node.html) // <h1>Hello World</h1>
}
}
This would allow plugins (including local use of gatsby-node.js) to access, use, and potentially extend the fields in question via onCreateNode.
This would also align gatsby-transformer-remark's behaviour with other plugins.
@KyleAMathews do you have any thoughts on this?
This issue was created at @KyleAMathews request. Based on a Conversation on Discord. See quotes below...
Kyle: html/excerpt are generated in response to queries — arguably we shouldn't do that for html but it makes sense for excerpt as the user can pass an arg for the excerpt length, etc.
Me: Thanks for the quick reply. Yes ... "html" was the big one. I was surprised that I couldn't access it from onCreateNode. I can live without excerpt and some of the other fields that take params.
Kyle: yeah... _we should probably change it_ — could you file an issue about it? It'd be a breaking change kinda so we should probably do it for v2
This issue was create at @KyleAMathews request. Based on a Conversation on Discord.
Ohhh, ok let me label this up as a feature then :D
Due to the high volume of issues, we're closing out older ones without recent activity. Please open a new issue if you need help!
Most helpful comment
Ohhh, ok let me label this up as a feature then :D