Skip to content

Commit

Permalink
feat(gatsby-source-shopify): download images option (#23840)
Browse files Browse the repository at this point in the history
* created PluginOptions Singleton class

Co-authored-by: Luke Bennett <[email protected]>

* set upnew plugin Options defintion

Co-authored-by: Luke Bennett <[email protected]>

* create default values for new options

Co-authored-by: Luke Bennett <[email protected]>

* if downloadImages set to false download default image instead

(caching will make that defaultImage only download once)

Co-authored-by: Luke Bennett <[email protected]>

* default image

* change default image

* add documentation

* small mistake fix

Co-authored-by: Luke Bennett <[email protected]>

* refact(plugin-options): follow filename convention

* style(plugin-options): delete semicolons

* style(plugin-options): prettier fixes

* style(gatsby-node): prettier fixes

* style(node): prettier fixes

* missed import reference

* lint error in document

* yarn format

* * removed pluginOption singleton
* removed and defaultUrl image config
* removed the default.png image
* fixed up documentation

* * pass though downloadImages config option in imageArgs
* if !downloadImages then don't download image

Co-authored-by: Luke Bennett <[email protected]>
Co-authored-by: Luke Bennett <[email protected]>
Co-authored-by: Gergő Gazda <[email protected]>
Co-authored-by: Kyle Mathews <[email protected]>
  • Loading branch information
5 people authored Jan 12, 2021
1 parent 9cb8eeb commit 931cc81
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/gatsby-source-shopify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ plugins: [
// Possible values are: 'shop' and 'content'.
// Defaults to ['shop', 'content'].
includeCollections: ["shop", "content"],
// Download Images Locally
// set to false if you plan on using shopify's CDN
downloadImages: true,

// Allow overriding the default queries
// This allows you to include/exclude extra fields when sourcing nodes
Expand Down
2 changes: 2 additions & 0 deletions packages/gatsby-source-shopify/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const sourceNodes = async (
verbose = true,
paginationSize = 250,
includeCollections = [SHOP, CONTENT],
downloadImages = true,
shopifyQueries = {},
}
) => {
Expand Down Expand Up @@ -89,6 +90,7 @@ export const sourceNodes = async (
cache,
getCache,
reporter,
downloadImages,
}

// Arguments used for node creation.
Expand Down
17 changes: 13 additions & 4 deletions packages/gatsby-source-shopify/src/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,24 @@ const { createNodeFactory, generateNodeId } = createNodeHelpers({

const downloadImageAndCreateFileNode = async (
{ url, nodeId },
{ createNode, createNodeId, touchNode, store, cache, getCache, reporter }
{
createNode,
createNodeId,
touchNode,
store,
cache,
getCache,
reporter,
downloadImages,
}
) => {
let fileNodeID
if (!downloadImages) return undefined

const mediaDataCacheKey = `${TYPE_PREFIX}__Media__${url}`
const cacheMediaData = await cache.get(mediaDataCacheKey)

if (cacheMediaData) {
fileNodeID = cacheMediaData.fileNodeID
const fileNodeID = cacheMediaData.fileNodeID
touchNode({ nodeId: fileNodeID })
return fileNodeID
}
Expand All @@ -49,7 +58,7 @@ const downloadImageAndCreateFileNode = async (
})

if (fileNode) {
fileNodeID = fileNode.id
const fileNodeID = fileNode.id
await cache.set(mediaDataCacheKey, { fileNodeID })
return fileNodeID
}
Expand Down

0 comments on commit 931cc81

Please sign in to comment.