Gatsby: Add support for querying SVGs as images

Created on 20 Dec 2017  路  5Comments  路  Source: gatsbyjs/gatsby

I think it would be great if public URLs for SVGs could be generated through ImageSharp. Currently, if I want to use vector and raster graphics interchangeably, I need to use some extra code similar to below:

let thumbnailSrc;
if (video.frontmatter.thumbnail != null) {
  thumbnailSrc =
    video.frontmatter.thumbnail.childImageSharp != null
      ? video.frontmatter.thumbnail.childImageSharp.sizes.src
      : `/${video.frontmatter.thumbnail.relativePath}`;
}

Also, I have to put all the related images to the /static folder and make them discoverable by gatsby-source-filesystem. Querying SVGs just like raster images would simplify this workflow by a lot.

Most helpful comment

I couldn't find the issue where this has been discussed before but what I suggest is that we add to File nodes (from gatsby-source-filesystem) the ability to "query" the file which will cause them to be copied to public/static with a content addressed path.

This would mean adding a new field e.g. publicLink (probably not the best name).

How's this sound? Would you like to do a PR?

All 5 comments

I couldn't find the issue where this has been discussed before but what I suggest is that we add to File nodes (from gatsby-source-filesystem) the ability to "query" the file which will cause them to be copied to public/static with a content addressed path.

This would mean adding a new field e.g. publicLink (probably not the best name).

How's this sound? Would you like to do a PR?

This sounds absolutely great! Unfortunately, I'm pretty busy nowadays, so I cannot do a PR.

@KyleAMathews Also, I think this proposal might be interesting for Gatsby v2: https://github.com/facebookincubator/create-react-app/issues/3722

publicURL has been added and works for me #3669
is this what you mean @kripod? or does it help?

@CanRau yeah, it鈥檚 fine now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Oppenheimer1 picture Oppenheimer1  路  3Comments

brandonmp picture brandonmp  路  3Comments

dustinhorton picture dustinhorton  路  3Comments

signalwerk picture signalwerk  路  3Comments

magicly picture magicly  路  3Comments