UNPKG

836 BPlain TextView Raw
1const extensions = [
2 `jpeg`,
3 `jpg`,
4 `png`,
5 `webp`,
6 `tif`,
7 `tiff`,
8 `gif`,
9 `mp4`,
10 `webm`,
11 `ogv`,
12].reduce((acc: any, v: string) => {
13 acc[v] = v
14 return acc
15}, {})
16
17interface Options {
18 node: any
19 actions: any
20 createNodeId: any
21}
22
23export default ({ node, actions, createNodeId }: Options) => {
24 const { createNode, createParentChildLink } = actions
25
26 if (!extensions[node.extension]) {
27 return
28 }
29
30 const imageNode = {
31 id: createNodeId(`${node.id} >> ImageCloudinary`),
32 children: [],
33 parent: node.id,
34 internal: {
35 contentDigest: `${node.internal.contentDigest}`,
36 type: `ImageCloudinary`,
37 },
38 }
39
40 createNode(imageNode)
41 createParentChildLink({ parent: node, child: imageNode })
42
43 return
44}