Created
November 9, 2018 18:59
-
-
Save KyleAMathews/00cdeb97c934ae833b20bc3f55aeea20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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