UNPKG

810 BJavaScriptView Raw
1const { supportedExtensions } = require(`./supported-extensions`)
2
3function unstable_shouldOnCreateNode({ node }) {
4 return node.internal.type === `File` && !!supportedExtensions[node.extension]
5}
6
7module.exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode
8
9module.exports.onCreateNode = async function onCreateNode({
10 node,
11 actions,
12 createNodeId,
13}) {
14 if (!unstable_shouldOnCreateNode({ node })) {
15 return
16 }
17
18 const { createNode, createParentChildLink } = actions
19
20 const imageNode = {
21 id: createNodeId(`${node.id} >> ImageSharp`),
22 children: [],
23 parent: node.id,
24 internal: {
25 contentDigest: `${node.internal.contentDigest}`,
26 type: `ImageSharp`,
27 },
28 }
29
30 createNode(imageNode)
31 createParentChildLink({ parent: node, child: imageNode })
32
33 return
34}