Skip to content

Instantly share code, notes, and snippets.

@KyleAMathews
Created November 9, 2018 18:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KyleAMathews/00cdeb97c934ae833b20bc3f55aeea20 to your computer and use it in GitHub Desktop.
Save KyleAMathews/00cdeb97c934ae833b20bc3f55aeea20 to your computer and use it in GitHub Desktop.
exports.onCreateNode = ({ node, actions, createNodeId, createContentDigest }) => {
const { createNode, createNodeField } = actions
if (node.internal.type === `NodeTypeWithMarkdownField`) {
const newNode = createNode({
id: createNodeId(`${node.id} markdown field`),
children: [],
parent: node.id,
internal: {
content: node.markdownField,
mediaType: `text/markdown`,
contentDigest: createContentDigest(node.markdownField),
type: `${node.internal.type}Markdown`,
},
})
// Add link to the new node
createNodeField({
node,
name: `markdownNode___NODE`,
value: newNode.id,
})
}
}
// You can now query the converted markdown field like { NodeTypeWithMarkdownField { fields { markdownNode { childMarkdownRemark { html } } } } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment