Skip to content

Instantly share code, notes, and snippets.

@stefanjudis
Created April 30, 2019 06:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanjudis/f7f23678ca610dad1534e4eed0dd42e9 to your computer and use it in GitHub Desktop.
Save stefanjudis/f7f23678ca610dad1534e4eed0dd42e9 to your computer and use it in GitHub Desktop.
Change URL to file node in Gatsby
const { createRemoteFileNode } = require(`gatsby-source-filesystem`);
exports.onCreateNode = async ({
actions,
node,
createNodeId,
store,
cache
}) => {
const { createNode } = actions;
if (node.internal.type === `googleSheetPodBotRow`) {
let fileNode;
try {
fileNode = await createRemoteFileNode({
url: node.episoderecordingurl,
parentNodeId: node.id,
store,
cache,
createNode,
createNodeId
});
} catch (e) {
console.log(e);
}
// Adds a field `localFile` to the node
// ___NODE appendix tells Gatsby that this field will link to another node
if (fileNode) {
node.localFile___NODE = fileNode.id;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment