This repository has been archived by the owner on Oct 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* cherrypick * add images to schema * chore: use new schema customization for linked file nodes * chore: set default publicKey * fix: add to assetIds if imageNode is defined * chore: use const vs let * chore(deps): update gatsby monorepo * refactor: tidy up gatsby config * docs: add downloadImageAssets config example * docs: add image assets instructions * fix: set empty images array Co-authored-by: Renovate Bot <[email protected]>
- Loading branch information
1 parent
b585cc0
commit 48683fd
Showing
12 changed files
with
2,103 additions
and
98 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
exports.onPreBootstrap = require('./gatsby/node/onPreBootstrap'); | ||
exports.sourceNodes = require('./gatsby/node/sourceNodes'); | ||
exports.createSchemaCustomization = require('./gatsby/node/createSchemaCustomization'); | ||
exports.onCreateNode = require('./gatsby/node/onCreateNode'); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const { createRemoteFileNode } = require('gatsby-source-filesystem'); | ||
|
||
const withPluginOptions = require('../../plugin-options'); | ||
|
||
const onCreateNode = async ( | ||
{ node, actions: { createNode }, createNodeId, store, cache }, | ||
pluginOptions | ||
) => { | ||
const { downloadImageAssets } = withPluginOptions(pluginOptions); | ||
|
||
node.images = []; | ||
|
||
if ( | ||
downloadImageAssets && | ||
node.internal.type === 'ChecProduct' && | ||
node.assets | ||
) { | ||
const getImageAssets = async () => { | ||
const assetIds = []; | ||
|
||
const processImageAssets = node.assets.map(async (asset) => { | ||
if (!asset.is_image) return; | ||
|
||
try { | ||
const imageNode = await createRemoteFileNode({ | ||
url: encodeURI(asset.url), | ||
store, | ||
cache, | ||
createNode, | ||
createNodeId, | ||
parentNodeId: node.id, | ||
}); | ||
|
||
if (imageNode) assetIds.push(imageNode.id); | ||
} catch (e) { | ||
console.error('gatsby-source-chec: ERROR', e); | ||
} | ||
}); | ||
|
||
await Promise.all(processImageAssets); | ||
|
||
return assetIds; | ||
}; | ||
|
||
node.images = await getImageAssets(); | ||
} | ||
}; | ||
|
||
module.exports = onCreateNode; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const withPluginOptions = require('../../plugin-options'); | ||
|
||
const onPreBootstrap = ({ reporter }, pluginOptions) => { | ||
const { publicKey } = withPluginOptions(pluginOptions); | ||
|
||
if (!publicKey) | ||
return reporter.panicOnBuild( | ||
`@chec/gatsby-source-chec: You must provide a 'publicKey' for your Chec store` | ||
); | ||
}; | ||
|
||
module.exports = onPreBootstrap; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const pluginOptions = (options) => ({ | ||
downloadImageAssets: false, | ||
...options, | ||
}); | ||
|
||
module.exports = pluginOptions; |
Oops, something went wrong.