Skip to content

Commit

Permalink
chore(gatsby-remark-images-contentful) Use createContentDigest helper (
Browse files Browse the repository at this point in the history
  • Loading branch information
gmertk authored and freiksenet committed Jun 4, 2019
1 parent 5579d86 commit af9fae3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/gatsby-remark-images-contentful/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"author": "Khaled Garbaya <[email protected]>",
"license": "MIT",
"peerDependencies": {
"gatsby": "^2.0.0"
"gatsby": "^2.0.15"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const createPluginOptions = (content, imagePaths = `/`) => {
dir: dirName,
}
},
createContentDigest: jest.fn().mockReturnValue(`contentDigest`),
}
}

Expand Down
17 changes: 11 additions & 6 deletions packages/gatsby-remark-images-contentful/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const crypto = require(`crypto`)
const select = require(`unist-util-select`)
const sharp = require(`./safe-sharp`)
const axios = require(`axios`)
Expand All @@ -15,7 +14,16 @@ const { buildResponsiveSizes } = require(`./utils`)
// 5. Set the html w/ aspect ratio helper.

module.exports = async (
{ files, markdownNode, markdownAST, pathPrefix, getNode, reporter, cache },
{
files,
markdownNode,
markdownAST,
pathPrefix,
getNode,
reporter,
cache,
createContentDigest,
},
pluginOptions
) => {
const defaults = {
Expand Down Expand Up @@ -50,10 +58,7 @@ module.exports = async (
const fileName = srcSplit[srcSplit.length - 1]
const options = _.defaults(pluginOptions, defaults)

const optionsHash = crypto
.createHash(`md5`)
.update(JSON.stringify(options))
.digest(`hex`)
const optionsHash = createContentDigest(options)

const cacheKey = `remark-images-ctf-${fileName}-${optionsHash}`
let cahedRawHTML = await cache.get(cacheKey)
Expand Down

0 comments on commit af9fae3

Please sign in to comment.