Skip to content

Commit

Permalink
[gatsby-transformer-sharp] add more details when reporting file copy …
Browse files Browse the repository at this point in the history
…error in ImageSharp.original field, honor path prefix when returning public url, use image name as part of image created in static directory
  • Loading branch information
pieh committed Jan 24, 2018
1 parent 7e04389 commit 6d8f17b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/gatsby-transformer-sharp/src/extend-node-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,33 @@ module.exports = ({ type, pathPrefix, getNodeAndSavePathDependency }) => {
async resolve(image, fieldArgs, context) {
const details = getNodeAndSavePathDependency(image.parent, context.path)
const dimensions = sizeOf(details.absolutePath)
const imageName = `${image.internal.contentDigest}${details.ext}`
const imageName = `${details.name}-${image.internal.contentDigest}${
details.ext
}`
const publicPath = path.join(
process.cwd(),
`public`,
`static/${imageName}`
`static`,
imageName
)

if (!fsExtra.existsSync(publicPath)) {
fsExtra.copy(details.absolutePath, publicPath, err => {
if (err) {
console.error(`error copying file`, err)
console.error(
`error copying file from ${
details.absolutePath
} to ${publicPath}`,
err
)
}
})
}

return {
width: dimensions.width,
height: dimensions.height,
src: `/static/` + imageName,
src: `${pathPrefix}/static/${imageName}`,
}
},
},
Expand Down

0 comments on commit 6d8f17b

Please sign in to comment.