Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure Jekyll to serve SVG?

Tags:

svg

jekyll

I use Jekyll for building my web site, and I want to start serving SVG. Browsers won't recognize SVG as an image unless it is sent with the proper MIME type. Unfortunately, Jekyll does not set the MIME type by default. (To be fair, Jekyll uses Webrick for the HTTP server)

How do I tell Jekyll to use the image/svg+xml mime type for SVG?

like image 744
Seth Ladd Avatar asked Dec 03 '12 16:12

Seth Ladd


1 Answers

  1. Create a _plugins directory in the root of your Jekyll project.
  2. Create a file called svg_mime_type.rb in _plugins
  3. Add this to svg_mime_type.rb:

    require 'webrick'
    include WEBrick
    WEBrick::HTTPUtils::DefaultMimeTypes.store 'svg', 'image/svg+xml'
    

That's it! Next time you start Jekyll, it will use the proper MIME type for SVG.

like image 150
Seth Ladd Avatar answered Sep 22 '22 16:09

Seth Ladd