I'm trying to filter the slug generated by Gatsby so I can remove white space and replace it with "-". I have Gatsby's reporter set to fire when onCreateNode is ran but it never seems to fire regardless of clearing the cache first. When I check in GraphiQL it shows no change to the slug. Here is my gastby-node.js onCreateNode:
exports.onCreateNode = ({ node, getNode, actions, reporter }) => {
reporter.info(`onCreateNode called from gatsby-node`)
const { createNodeField } = actions
if (node.internal.type === `MarkdownRemark`) {
const slug = createFilePath({ node, getNode, basePath: `posts` }).replace(
' ',
'-'
)
createNodeField({
node,
name: `slug`,
value: slug
})
}}
Any input would be greatly appreciated!
There ended up being two instances of onCreateNode()
in my gatsby-node.js file. Only one of them was being called during build. Removing the second instance of onCreateNode()
solved my problem.