Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gatsby-source-shopify): download images option #23840

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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