Skip to content

Commit

Permalink
WIP - support traced svgs again
Browse files Browse the repository at this point in the history
  • Loading branch information
axe312ger committed Dec 22, 2020
1 parent 3c36664 commit c75a363
Showing 1 changed file with 40 additions and 23 deletions.
63 changes: 40 additions & 23 deletions packages/gatsby-source-contentful/src/extend-node-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit c75a363

Please sign in to comment.