├── .gitignore ├── Gemfile ├── LICENSE ├── Rakefile ├── Readme.md ├── jekyll-press.gemspec └── lib ├── jekyll-press.rb └── jekyll-press └── version.rb /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .yardoc 6 | Gemfile.lock 7 | InstalledFiles 8 | _yardoc 9 | coverage 10 | doc/ 11 | lib/bundler/man 12 | pkg 13 | rdoc 14 | spec/reports 15 | test/tmp 16 | test/version_tmp 17 | tmp 18 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in jekyll-press.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Stereobooster 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | require "bundler/gem_tasks" 3 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # jekyll-press 2 | Minifier plugin for jekyll. Minifies all html, js, css files. Simple just drop it in solution. No Java required. 3 | 4 | This plugin: 5 | - compress html with the help of [html_press](https://github.com/stereobooster/html_press) 6 | - compress JavaScript files with the help of [uglifier](https://github.com/lautis/uglifier) 7 | - compress css files with the help of [css_press](https://github.com/stereobooster/css_press) 8 | 9 | ## Alternative 10 | 11 | Gulp based workflow see: [sondr3/generator-jekyllized](/sondr3/generator-jekyllized) 12 | 13 | ## Installation 14 | 15 | ### Bundler 16 | Add this line to your application's `Gemfile`: 17 | ```ruby 18 | gem 'jekyll-press' 19 | ``` 20 | 21 | And then execute: 22 | ```bash 23 | $ bundle 24 | ``` 25 | 26 | ### Standalone 27 | Execute: 28 | ```bash 29 | $ gem install jekyll-press 30 | ``` 31 | 32 | ## Usage 33 | 34 | ### With Bundler (recomended) 35 | Create the following plugin in your projects _plugins directory. 36 | 37 | ```ruby 38 | # _plugins/bundler.rb 39 | require "rubygems" 40 | require "bundler/setup" 41 | Bundler.require(:default) 42 | ``` 43 | 44 | This will automatically require all of the gems specified in your Gemfile. 45 | 46 | ### Standalone 47 | Create the following plugin in your projects _plugins directory. 48 | 49 | ```ruby 50 | # _plugins/jekyll-press-plugin.rb 51 | require 'jekyll-press' 52 | ``` 53 | 54 | ### Settings 55 | 56 | ```yaml 57 | jekyll-press: 58 | exclude: 'atom.xml' # Exclude files from processing - file name, glob pattern or array of file names and glob patterns 59 | js_options: {} # js minifier options 60 | css_options: {} # css minifier options 61 | html_options: {} # html minifier options 62 | ``` 63 | 64 | ## TODO 65 | - add test: run against simple jekyll site and check if there is no errors 66 | - Minify JPEGs with [`jpegtran`](/cmer/jpegtran) or `smush.it` ([smusher](/grosser/smusher)) 67 | - Minify PNGs with [`optipng`](/martinkozak/optipng) or `smush.it` ([smusher](/grosser/smusher)) 68 | - Auto CSS sprites (for example [sprite factory](/jakesgordon/sprite-factory/)) 69 | 70 | ## Contributing 71 | 1. Fork it 72 | 2. Create your feature branch (`git checkout -b my-new-feature`) 73 | 3. Commit your changes (`git commit -am 'Added some feature'`) 74 | 4. Push to the branch (`git push origin my-new-feature`) 75 | 5. Create new Pull Request 76 | -------------------------------------------------------------------------------- /jekyll-press.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | require File.expand_path('../lib/jekyll-press/version', __FILE__) 3 | 4 | Gem::Specification.new do |gem| 5 | gem.authors = ["sterebooster"] 6 | gem.email = ["stereobooster@gmail.com"] 7 | gem.description = %q{Minifier plugin for jekyll. Minifies all html, js, css files. Simple just drop it in solution. No Java required} 8 | gem.summary = %q{Minifier plugin for jekyll. This plugin compress html with the help of html_press, compress JavaScript files with the help of uglifier, compress css files with the help of css_press} 9 | gem.homepage = "http://github.com/stereobooster/jekyll-press" 10 | gem.license = "MIT" 11 | 12 | gem.files = `git ls-files`.split($\) 13 | gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } 14 | gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) 15 | gem.name = "jekyll-press" 16 | gem.require_paths = ["lib"] 17 | gem.version = Jekyll::Press::VERSION 18 | 19 | gem.add_dependency "jekyll" 20 | gem.add_dependency "html_press", ">= 0.8.2" 21 | gem.add_dependency "multi_css", ">= 0.1.0" 22 | gem.add_dependency "multi_js", ">= 0.1.0" 23 | 24 | gem.add_development_dependency "rake" 25 | end 26 | -------------------------------------------------------------------------------- /lib/jekyll-press.rb: -------------------------------------------------------------------------------- 1 | require "jekyll-press/version" 2 | 3 | require 'html_press' 4 | require 'multi_css' 5 | require 'multi_js' 6 | 7 | module Jekyll 8 | module Compressor 9 | def exclude?(dest, dest_path) 10 | res = false 11 | file_name = dest_path.slice(dest.length+1..dest_path.length) 12 | exclude = @site.config['jekyll-press'] && @site.config['jekyll-press']['exclude'] 13 | if exclude 14 | if exclude.is_a? String 15 | exclude = [exclude] 16 | end 17 | exclude.each do |e| 18 | if e == file_name || File.fnmatch(e, file_name) 19 | res = true 20 | break 21 | end 22 | end 23 | end 24 | res 25 | end 26 | 27 | def output_file(dest, content) 28 | FileUtils.mkdir_p(File.dirname(dest)) 29 | File.open(dest, 'w') do |f| 30 | f.write(content) 31 | end 32 | end 33 | 34 | def output_html(path, content) 35 | output_file(path, HtmlPress.press(content, @site.config['jekyll-press'] && @site.config['jekyll-press']['html_options'] || {})) 36 | end 37 | 38 | def output_js(path, content) 39 | output_file(path, MultiJs.compile(content, @site.config['jekyll-press'] && @site.config['jekyll-press']['js_options'] || {})) 40 | rescue MultiJs::ParseError => e 41 | warn "Warning: parse error in #{path}. Don't panic - copying initial file" 42 | warn "Details: #{e.message.strip}" 43 | output_file(path, content) 44 | end 45 | 46 | def output_css(path, content) 47 | output_file(path, MultiCss.min(content, @site.config['jekyll-press'] && @site.config['jekyll-press']['css_options'] || {})) 48 | rescue MultiCss::ParseError => e 49 | warn "Warning: parse error in #{path}. Don't panic - copying initial file" 50 | warn "Details: #{e.message.strip}" 51 | output_file(path, content) 52 | end 53 | end 54 | 55 | class Post 56 | include Compressor 57 | 58 | def write(dest) 59 | dest_path = destination(dest) 60 | output_html(dest_path, output) 61 | end 62 | end 63 | 64 | class Page 65 | include Compressor 66 | 67 | def write(dest) 68 | dest_path = destination(dest) 69 | if exclude?(dest, dest_path) 70 | output_file(dest_path, output) 71 | else 72 | output_html(dest_path, output) 73 | end 74 | end 75 | end 76 | 77 | class StaticFile 78 | include Compressor 79 | 80 | def copy_file(path, dest_path) 81 | FileUtils.mkdir_p(File.dirname(dest_path)) 82 | FileUtils.cp(path, dest_path) 83 | end 84 | 85 | def write(dest) 86 | dest_path = destination(dest) 87 | 88 | return false if File.exist?(dest_path) and !modified? 89 | @@mtimes[path] = mtime 90 | 91 | case File.extname(dest_path) 92 | when '.js' 93 | if dest_path =~ /.min.js$/ 94 | copy_file(path, dest_path) 95 | else 96 | output_js(dest_path, File.read(path)) 97 | end 98 | when '.css' 99 | if dest_path =~ /.min.css$/ 100 | copy_file(path, dest_path) 101 | else 102 | output_css(dest_path, File.read(path)) 103 | end 104 | else 105 | copy_file(path, dest_path) 106 | end 107 | 108 | true 109 | end 110 | end 111 | end -------------------------------------------------------------------------------- /lib/jekyll-press/version.rb: -------------------------------------------------------------------------------- 1 | module Jekyll 2 | module Press 3 | VERSION = "0.2.1" 4 | end 5 | end 6 | --------------------------------------------------------------------------------