Skip to content

Commit

Permalink
[1.0] Ignore SVGs in gatsby-remark-responsive-image (#1145) (#1157)
Browse files Browse the repository at this point in the history
* Ignore SVGs in gatsby-remark-responsive-image

…and instead just copy them alongside GIFs in gatsby-remark-copy-linked-files.

* Fix reference to node `contentDigest`

@see #960
@see https://github.com/gatsbyjs/gatsby/releases/tag/v1.0.0-alpha15

* Check node extension instead of sliced image.url
  • Loading branch information
fk authored and KyleAMathews committed Jun 13, 2017
1 parent 0069ba4 commit 51bdc9d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
17 changes: 13 additions & 4 deletions packages/gatsby-remark-copy-linked-files/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ module.exports = ({ files, markdownNode, markdownAST, getNode }) => {
const newPath = path.join(
process.cwd(),
`public`,
`${linkNode.contentDigest}.${linkNode.extension}`
`${linkNode.internal.contentDigest}.${linkNode.extension}`
)
const relativePath = path.join(
`/${linkNode.contentDigest}.${linkNode.extension}`
`/${linkNode.internal.contentDigest}.${linkNode.extension}`
)
link.url = `${relativePath}`
if (!fsExtra.existsSync(newPath)) {
Expand All @@ -44,9 +44,18 @@ module.exports = ({ files, markdownNode, markdownAST, getNode }) => {
visitor(link)
})

// Also copy gifs since Sharp can't process them.
// Also copy gifs since Sharp can't process them,
// and svgs since we exclude them from the image processing pipeline in
// gatsby-remark-responsive-image
visit(markdownAST, `image`, image => {
if (image.url.slice(-3) === `gif`) {
const imagePath = path.join(getNode(markdownNode.parent).dir, image.url)
const imageNode = _.find(files, file => {
if (file && file.absolutePath) {
return file.absolutePath === imagePath
}
return null
})
if (imageNode.extension === `gif` || imageNode.extension === `svg`) {
visitor(image)
}
})
Expand Down
11 changes: 9 additions & 2 deletions packages/gatsby-remark-responsive-image/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ module.exports = ({
imageNodes.map(
node =>
new Promise((resolve, reject) => {
// Ignore gifs as we can't process them.
if (isRelativeUrl(node.url) && node.url.slice(-3) !== `gif`) {
const fileType = node.url.slice(-3)

// Ignore gifs as we can't process them,
// svgs as they are already responsive by definition
if (
isRelativeUrl(node.url) &&
fileType !== `gif` &&
fileType !== `svg`
) {
const imagePath = path.posix.join(
getNode(markdownNode.parent).dir,
node.url
Expand Down

0 comments on commit 51bdc9d

Please sign in to comment.