Files
30-seconds-of-code/node_modules/gatsby-transformer-sharp/on-node-create.js
2019-08-20 15:52:05 +02:00

41 lines
672 B
JavaScript

"use strict";
const supportedExtensions = {
jpeg: true,
jpg: true,
png: true,
webp: true,
tif: true,
tiff: true
};
module.exports = async function onCreateNode({
node,
actions,
createNodeId
}) {
const {
createNode,
createParentChildLink
} = actions;
if (!supportedExtensions[node.extension]) {
return;
}
const imageNode = {
id: createNodeId(`${node.id} >> ImageSharp`),
children: [],
parent: node.id,
internal: {
contentDigest: `${node.internal.contentDigest}`,
type: `ImageSharp`
}
};
createNode(imageNode);
createParentChildLink({
parent: node,
child: imageNode
});
return;
};