5

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?

4

1 回答 1

10
  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.

于 2012-12-03T16:00:22.990 回答