Created
April 30, 2019 06:24
-
-
Save stefanjudis/f7f23678ca610dad1534e4eed0dd42e9 to your computer and use it in GitHub Desktop.
Change URL to file node in Gatsby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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