monoの開発ブログ

Octopressでgzip

nginxのgzip_staticを使うために、gzip圧縮したファイルを生成しておくメモ。

  gem 'parallel'
require 'zlib'
require 'parallel'

desc "Generate jekyll site"
task :generate do
  raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
  puts "## Generating Site with Jekyll"
  system "compass compile --css-dir #{source_dir}/stylesheets"
  system "jekyll"
  Parallel.each(Dir.glob("#{public_dir}/**/*.{css,html,js,xml}")) do |f|
    open(f) do |src|
      Zlib::GzipWriter.open("#{f}.gz") do |gz|
        gz.puts src.read
      end
    end
  end
end