You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
in some cases the remoteFile may not be there and cannot be created. this will lead to a problem with later plugins in the structure. now i try to integrate a simple fallback to an local image in my static folder.
sadly i am failing to source the image node ... this is what i normally do without any trouble:
let fileNode = await createRemoteFileNode({
name: `${node.frontmatter.title}`,
publicURL: fullHdPoster,
url: fullHdPoster,
parentNodeId: node.id, // id of the parent node of the fileNode you are going to create
createNode, // helper function in gatsby-node to generate the node
createNodeId, // helper function in gatsby-node to generate the node id
cache, // Gatsby's cache
store, // Gatsby's Redux store
})
console.log(fileNode);
if (fileNode) {
node.frontmatter.videoPoster___NODE = fileNode.id
}
but how i include a file from static folder if (for any reasons) the createRemoteFileNode is not possible/not wanted?
i tried to integrate the placeholder image like that without luck.
const imgPath ='./static/img-placeholder.jpg'
const { name, ext } = path.parse(imgPath) // get file name & extension
const absolutePath = path.resolve(__dirname, imgPath)
const data = {
name,
ext,
absolutePath,
extension: ext.substring(1),
}
const imageNode = {
...data,
createNode, // helper function in gatsby-node to generate the node
id: createNodeId(`${node.frontmatter.title}_placeholder`),
parentNodeId: node.id,
children: [],
internal: {
type: 'PlaceholderFile',
mediaType: 'image/jpeg',
contentDigest: createContentDigest(data),
}
}
createNode(imageNode)
node.frontmatter.videoPoster___NODE = imageNode.id
sadly it fails with the next plugin, wants to have an image ...
Is there something like createFileNode? for a file from Staticfolder e.g.?
Edit: it fails in build because missing the
childImageSharp of this placeholder image.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
in some cases the remoteFile may not be there and cannot be created. this will lead to a problem with later plugins in the structure. now i try to integrate a simple fallback to an local image in my static folder.
sadly i am failing to source the image node ... this is what i normally do without any trouble:
but how i include a file from static folder if (for any reasons) the createRemoteFileNode is not possible/not wanted?
i tried to integrate the placeholder image like that without luck.
sadly it fails with the next plugin, wants to have an image ...
Is there something like createFileNode? for a file from Staticfolder e.g.?
Edit: it fails in build because missing the
childImageSharp of this placeholder image.
Beta Was this translation helpful? Give feedback.
All reactions