Sha256: 679114ab3b86888c32be1be8594b9bc43cf569d71ffa9bb8e2d651d6c3490e56

Contents?: true

Size: 856 Bytes

Versions: 2

Compression:

Stored size: 856 Bytes

Contents

require "zlib"

module Jekyll
  module Gzip
    class Compressor
      ZIPPABLE_EXTENSIONS = [
        '.html',
        '.css',
        '.js',
        '.txt',
        '.ttf',
        '.atom',
        '.stl',
        '.xml',
        '.svg',
        '.eot'
      ]

      attr_reader :site

      def initialize(site)
        @site = site
      end

      def compress_file(file_name)
        return unless ZIPPABLE_EXTENSIONS.include?(File.extname(file_name))
        zipped = "#{file_name}.gz"
        Zlib::GzipWriter.open(zipped, Zlib::BEST_COMPRESSION) do |gz|
          gz.mtime = File.mtime(file_name)
          gz.orig_name = file_name
          gz.write IO.binread(file_name)
        end
      end

      def compress
        site.each_site_file do |file|
          compress_file(file.destination(site.dest))
        end
      end
    end
  end
end 

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jekyll-gzip-1.1.0 lib/jekyll/gzip/compressor.rb
jekyll-gzip-1.0.0 lib/jekyll/gzip/compressor.rb