diff --git a/packages/gatsby-source-contentful/src/extend-node-type.js b/packages/gatsby-source-contentful/src/extend-node-type.js index 608357ce9d88f..9cd91c7d37bbf 100644 --- a/packages/gatsby-source-contentful/src/extend-node-type.js +++ b/packages/gatsby-source-contentful/src/extend-node-type.js @@ -14,7 +14,9 @@ const { const qs = require(`qs`) const base64Img = require(`base64-img`) const { generateImageData } = require(`gatsby-plugin-image`) -const { getGatsbyImageFieldConfig } = require(`gatsby-plugin-image/graphql`) +const { + getGatsbyImageFieldConfig, +} = require(`gatsby-plugin-image/dist/resolver-utils`) const { stripIndent } = require(`common-tags`) const cacheImage = require(`./cache-image`) @@ -192,28 +194,6 @@ const fitMap = new Map([ [`thumb`, `cover`], ]) -const resolveGatsbyImageData = async (image, options) => { - const { baseUrl, ...sourceMetadata } = getBasicImageProps(image, options) - - return generateImageData({ - ...options, - pluginName: `gatsby-source-contentful`, - sourceMetadata, - filename: baseUrl, - placeholderURL: - options.placeholder === `blurred` - ? await getBase64Image({ - baseUrl, - }) - : undefined, - generateImageSource, - fit: fitMap.get(options.resizingBehavior), - options, - }) -} - -exports.resolveGatsbyImageData = resolveGatsbyImageData - const resolveFixed = (image, options) => { if (!isImage(image)) return null @@ -682,6 +662,43 @@ exports.extendNodeType = ({ type, store, reporter }) => { }) } + const resolveGatsbyImageData = async (image, options) => { + const { baseUrl, ...sourceMetadata } = getBasicImageProps(image, options) + + const imageProps = generateImageData({ + ...options, + pluginName: `gatsby-source-contentful`, + sourceMetadata, + filename: baseUrl, + generateImageSource, + fit: fitMap.get(options.resizingBehavior), + options, + }) + + let placeholderDataURI = null + + if (options.placeholder === `blurred`) { + placeholderDataURI = await getBase64Image({ + baseUrl, + }) + } + + if (options.placeholder === `tracedSVG`) { + placeholderDataURI = await getTracedSVG({ + image, + options, + }) + } + + if (placeholderDataURI) { + imageProps.placeholder = { fallback: placeholderDataURI } + } + + console.log({ imageProps }) + + return imageProps + } + // TODO: Remove resolutionsNode and sizesNode for Gatsby v3 const fixedNode = fixedNodeType({ name: `ContentfulFixed`, getTracedSVG }) const resolutionsNode = fixedNodeType({