Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 11661

Connect the two created markdown and image nodes to original one

$
0
0

Hi I have a Graph_page nodes and it has two fields image and body. Image is the image path from which I create remoteAsset so that Image CDN works, I do the same with body so that it can be parsed by remark.

But for the love of God I can't figure out how to connect those two nodes per Graph_page so tha I can query it.

export const onCreateNode: GatsbyNode["onCreateNode"] = async ({  node,  actions: { createNode, createNodeField },  createNodeId,  createContentDigest,}) => {  if (node.internal.type === "Graph_pages") {    const nodeId = `MarkdownNode:${createNodeId(`${node.id}-body`)}`;    const mdNode = {      id: nodeId,      parent: node.id,      internal: {        type: `MarkdownNode`,        mediaType: "text/markdown",        content: he.decode(node["body"]),        contentDigest: `contentDigest`,      },    };    createNode(mdNode);    const pathname = new URL(node.image).pathname;    const fileNameWithExtension = path.basename(pathname);    const extension = path.extname(fileNameWithExtension);    const fileNameWithoutExtension = path.basename(      fileNameWithExtension,      extension    );    const imageAttr = await probe(node.image);    const imageData = {      url: `https://XXXXX.netlify.app/.netlify/images?url=${node.image}`,      placeholderUrl: `https://XXXXX.netlify.app/.netlify/images?url=${node.image}&w=%width%&h=%height%`,      mimeType: imageAttr.mime,      filename: fileNameWithoutExtension,      width: imageAttr.width,      height: imageAttr.height,      alt: `Red and rosa infinity thingy floating in air`,    };    const assetId = `ImageAsset:${createNodeId(`${node.id}-image`)}`;    createNode({      ...imageData,      id: assetId,      parent: node.id,      children: [],      internal: {        type: `ImageAsset`,        contentDigest: createContentDigest(imageData),      },    });  }};

Viewing all articles
Browse latest Browse all 11661

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>