question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for querying SVGs as images

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
KyleAMathewscommented, Dec 20, 2017

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?

1reaction
kripodcommented, Mar 4, 2018

@CanRau yeah, it’s fine now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using SVG with Media Queries - SitePoint
By using SVGs with media queries, we can change their appearance based on user interaction or viewport size, and use them in multiple ......
Read more >
SVG (basic support) | Can I use... Support tables for ... - CanIUse
"Can I use" provides up-to-date browser support tables for support of front-end ... Method of displaying basic Vector Graphics features using the embed...
Read more >
Media Queries in SVG images - Cloud Four
The really cool thing about the way media queries work inside SVG is that they react to the viewport of the image itself,...
Read more >
Accessible SVGs | CSS-Tricks
Screen reader traversable – Make sure the SVG is traversable in all browsers by adding role="group" to the <svg> . According to the...
Read more >
How to Use SVG Images in CSS and HTML – A Tutorial for ...
Assuming you downloaded the SVG image from unDraw and renamed it to happy.svg, you can go ahead and add the code snippet above...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found