Skip to content

Commit

Permalink
chore(gatsby-transformer-screenshot): Use createContentDigest helper …
Browse files Browse the repository at this point in the history
…for file name (#18830)

* update gatsby plugins to use new createContentDigest helper at gatsby-transformer-screenshot & replace peerDependency for gatsby-transformer-sqip

* change to use contentDigest

* Update yarn.lock

* Make changes from review

* Move dependency to right package
  • Loading branch information
KorawitRupanya authored and GatsbyJS Bot committed Oct 28, 2019
1 parent 5fc1356 commit 45acff9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
10 changes: 3 additions & 7 deletions packages/gatsby-transformer-screenshot/lambda/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const setup = require(`./starter-kit/setup`)

const crypto = require(`crypto`)
const { createContentDigest } = require(`gatsby-core-utils`)

const AWS = require(`aws-sdk`)
const s3 = new AWS.S3({
Expand Down Expand Up @@ -55,12 +55,8 @@ exports.run = async (browser, url, width, height, fullPage) => {
throw new Error(`invalid bucket ${process.env.S3_BUCKET}`)
}

const keyBase = `${url}-(${width},${height})`
const digest = crypto
.createHash(`md5`)
.update(keyBase)
.digest(`hex`)
const key = `${digest}.png`
const contentDigest = createContentDigest({ url, width, height })
const key = `${contentDigest}.png`

const screenshotUrl = `https://s3-${region}.amazonaws.com/${
process.env.S3_BUCKET
Expand Down
3 changes: 2 additions & 1 deletion packages/gatsby-transformer-screenshot/lambda/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"dependencies": {
"gatsby-core-utils": "^1.0.15",
"puppeteer": "0.13.0",
"tar": "^4.4.13"
},
Expand All @@ -9,4 +10,4 @@
"keywords": [
"gatsby-plugin"
]
}
}

0 comments on commit 45acff9

Please sign in to comment.