├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── lib ├── octopress-minify-html.rb └── octopress-minify-html │ └── version.rb ├── octopress-minify-html.gemspec └── test ├── _clash.yml ├── _collection_test └── test.md ├── _config.yml ├── _config_html_press.yml ├── _env-dev.yml ├── _env-prod.yml ├── _expected ├── compressed-configured │ ├── collection_test │ │ └── test.html │ ├── index.html │ └── uncompressed.txt ├── compressed │ ├── collection_test │ │ └── test.html │ ├── index.html │ └── uncompressed.txt └── uncompressed │ ├── collection_test │ └── test.html │ ├── index.html │ └── uncompressed.txt ├── _minify-false.yml ├── _minify-true.yml ├── index.md └── uncompressed.txt /.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 | _site 19 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.0.0 4 | script: bundle exec clash test 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ### 1.3.1 (2016-02-04) 4 | - New: Support for Jekyll 3.1. 5 | 6 | ### 1.3.0 (2015-07-07) 7 | - New: Support for Jekyll 3. 8 | 9 | ### 1.2.4 (2015-03-23) 10 | 11 | - Added `html_press` configuration for setting compression options. 12 | 13 | ### 1.2.3 (2015-03-09) 14 | 15 | - Fix: Improved method of checking if a page output will be an HTML page. 16 | 17 | ### 1.2.2 (2015-02-25) 18 | 19 | - Fix: No longer compresses non-HTML pages. 20 | 21 | ### 1.2.1 (2015-01-05) 22 | 23 | - Rewritten on top of Octopress Hooks. 24 | 25 | ### 1.2.0 (2015-01-05) 26 | 27 | - Added support for Jekyll collections. 28 | - Renamed to octopress-minify-html. 29 | 30 | ### 1.1.0 (2013-11-02) 31 | 32 | - [CHANGE] Now minifies HTML by default. Disable by setting config `env` to something other than `production` or by setting config `minify_html: false`. 33 | 34 | ### 1.0.1 (2013-10-25) 35 | 36 | - Now compatible with Jekyll 0.12+ 37 | - Added tests for Jekyll 0.12 and Jekyll 1.0 38 | 39 | ### 1.0.0 (2013-10-24) 40 | 41 | Initial Release 42 | 43 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in jekyll-minify-html.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Brandon Mathis 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. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Octopress Minify Html 2 | 3 | [](http://badge.fury.io/rb/octopress-minify-html) 4 | [](https://travis-ci.org/octopress/minify-html) 5 | 6 | 7 | Minify Jekyll's HTML output with [HtmlPress](https://github.com/stereobooster/html_press) 8 | 9 | ## Installation 10 | 11 | ### Using Bundler 12 | 13 | Add this gem to your site's Gemfile in the `:jekyll_plugins` group: 14 | 15 | group :jekyll_plugins do 16 | gem 'octopress-minify-html' 17 | end 18 | 19 | Then install the gem with Bundler 20 | 21 | $ bundle 22 | 23 | ### Manual Installation 24 | 25 | $ gem install octopress-minify-html 26 | 27 | Then add the gem to your Jekyll configuration. 28 | 29 | gems: 30 | - octopress-minify-html 31 | 32 | ## Usage 33 | 34 | After installing, Jekyll's HTML output will be minified by default. If you configure `env` in your Jekyll configuration, HTML will be minified only when 35 | `env` is set to production. 36 | 37 | ```yml 38 | env: production 39 | ``` 40 | 41 | You can override the default behavior by setting the `minify_html` config. 42 | For example, this will disable minification, regardless of your `env` setting. 43 | 44 | ```yml 45 | minify_html: false 46 | ``` 47 | 48 | ## HtmlPress Configuration: 49 | 50 | You can set configuration options for [HtmlPress](https://github.com/stereobooster/html_press) in your Jekyll configuration like this: 51 | 52 | ``` 53 | html_press: 54 | unquoted_attributes: false 55 | drop_empty_values: false 56 | strip_crlf: false 57 | js_minifier_options: false 58 | ``` 59 | 60 | ## Contributing 61 | 62 | 1. Fork it 63 | 2. Create your feature branch (`git checkout -b my-new-feature`) 64 | 3. Commit your changes (`git commit -am 'Add some feature'`) 65 | 4. Push to the branch (`git push origin my-new-feature`) 66 | 5. Create new Pull Request 67 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | -------------------------------------------------------------------------------- /lib/octopress-minify-html.rb: -------------------------------------------------------------------------------- 1 | require 'html_press' 2 | 3 | require 'octopress-minify-html/version' 4 | 5 | module Octopress 6 | module MinifyHTML 7 | 8 | extend self 9 | 10 | def minify(item) 11 | options = symbolize(item.site.config['html_press'] || {}) 12 | if minify?(item) 13 | HtmlPress.press(item.output, options) 14 | else 15 | item.output 16 | end 17 | end 18 | 19 | def minify?(item) 20 | config = item.site.config 21 | if item.destination(config['destination']).end_with?('html') 22 | minify = config['minify_html'] 23 | production = config['env'].nil? || config['env'] =~ /production/i 24 | 25 | # Minify if configuration explicitly requires minification 26 | # or if Jekyll env is production 27 | minify || (minify.nil? && production) 28 | end 29 | end 30 | 31 | def symbolize(obj) 32 | return obj.reduce({}) do |memo, (k, v)| 33 | memo.tap { |m| m[k.to_sym] = symbolize(v) } 34 | end if obj.is_a? Hash 35 | 36 | return obj.reduce([]) do |memo, v| 37 | memo << symbolize(v); memo 38 | end if obj.is_a? Array 39 | 40 | obj 41 | end 42 | 43 | if defined?(Jekyll::Hooks) 44 | Jekyll::Hooks.register [:posts, :pages, :documents], :post_render do |item| 45 | item.output = MinifyHTML.minify(item) 46 | end 47 | else 48 | require 'octopress-hooks' 49 | class MinifyPage < Octopress::Hooks::All 50 | def post_render(item) 51 | item.output = MinifyHTML.minify(item) 52 | end 53 | end 54 | end 55 | end 56 | end 57 | 58 | 59 | if defined? Octopress::Docs 60 | Octopress::Docs.add({ 61 | name: "Octopress Minify HTML", 62 | gem: "octopress-minify-html", 63 | description: "Automatically minifies HTML output for your Jekyll site.", 64 | path: File.expand_path(File.join(File.dirname(__FILE__), "../")), 65 | source_url: "https://github.com/octopress/minify-html", 66 | version: Octopress::MinifyHTML::VERSION 67 | }) 68 | end 69 | -------------------------------------------------------------------------------- /lib/octopress-minify-html/version.rb: -------------------------------------------------------------------------------- 1 | module Octopress 2 | module MinifyHTML 3 | VERSION = "1.3.1" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /octopress-minify-html.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'octopress-minify-html/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "octopress-minify-html" 8 | spec.version = Octopress::MinifyHTML::VERSION 9 | spec.authors = ["Brandon Mathis"] 10 | spec.email = ["brandon@imathis.com"] 11 | spec.description = %q{Minify Jekyll's HTML output using html_press} 12 | spec.summary = %q{Minify Jekyll's HTML output using html_press} 13 | spec.homepage = "https://github.com/octopress/minify-html" 14 | spec.license = "MIT" 15 | 16 | spec.files = `git ls-files`.split("\n").grep(%r{^(bin\/|lib\/|assets\/|changelog|readme|license)}i) 17 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 18 | spec.require_paths = ["lib"] 19 | 20 | spec.add_development_dependency "bundler", "~> 1.3" 21 | spec.add_development_dependency "rake" 22 | spec.add_development_dependency "clash" 23 | 24 | spec.add_runtime_dependency "jekyll", ">= 2.0" 25 | spec.add_runtime_dependency "html_press", "~> 0.8" 26 | spec.add_runtime_dependency "octopress-hooks" 27 | 28 | if RUBY_VERSION >= "2" 29 | spec.add_development_dependency "octopress-debugger" 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /test/_clash.yml: -------------------------------------------------------------------------------- 1 | - 2 | title: Standard build 3 | build: true 4 | compare: _expected/compressed _site 5 | - 6 | title: Uncompressed build 7 | build: true 8 | compare: _expected/uncompressed _site 9 | config: 10 | jekyll: 11 | - _config.yml 12 | - _minify-false.yml 13 | - 14 | title: Configure HtmlPress 15 | build: true 16 | compare: _expected/compressed-configured _site 17 | config: 18 | jekyll: 19 | - _config.yml 20 | - _config_html_press.yml 21 | - 22 | title: ENV production build 23 | build: true 24 | compare: _expected/compressed _site 25 | config: 26 | jekyll: 27 | - _config.yml 28 | - _env-prod.yml 29 | - 30 | title: ENV development build 31 | build: true 32 | compare: _expected/uncompressed _site 33 | config: 34 | jekyll: 35 | - _config.yml 36 | - _env-dev.yml 37 | - 38 | title: ENV production override build 39 | build: true 40 | compare: _expected/uncompressed _site 41 | config: 42 | jekyll: 43 | - _config.yml 44 | - _env-prod.yml 45 | - _minify-false.yml 46 | - 47 | title: ENV development override build 48 | build: true 49 | compare: _expected/compressed _site 50 | config: 51 | jekyll: 52 | - _config.yml 53 | - _env-dev.yml 54 | - _minify-true.yml 55 | -------------------------------------------------------------------------------- /test/_collection_test/test.md: -------------------------------------------------------------------------------- 1 | --- 2 | --- 3 | 4 | # Test 5 | 6 |
Here's a code block.
2 | Don't compress this!
3 |
4 | ^ empty line suckas!
5 | What are you going to do about it?
6 | I'm a code block!
7 |
OK.
This is probably good enough.
Peace out.
-------------------------------------------------------------------------------- /test/_expected/compressed-configured/index.html: -------------------------------------------------------------------------------- 1 |Here's a code block.
2 | Don't compress this!
3 |
4 | ^ empty line suckas!
5 | What are you going to do about it?
6 | I'm a code block!
7 |
OK.
This is probably good enough.
Peace out.
Here's a code block.
2 | Don't compress this!
3 |
4 | ^ empty line suckas!
5 | What are you going to do about it?
6 | I'm a code block!
7 |
OK.
This is probably good enough.
Peace out.
-------------------------------------------------------------------------------- /test/_expected/compressed/index.html: -------------------------------------------------------------------------------- 1 |Here's a code block.
2 | Don't compress this!
3 |
4 | ^ empty line suckas!
5 | What are you going to do about it?
6 | I'm a code block!
7 |
OK.
This is probably good enough.
Peace out.
Here's a code block.
8 | Don't compress this!
9 |
10 | ^ empty line suckas!
11 | What are you going to do about it?
12 | I'm a code block!
13 |
14 | OK.
17 | 18 |This is probably good enough.
19 | 20 |Peace out.
21 | -------------------------------------------------------------------------------- /test/_expected/uncompressed/index.html: -------------------------------------------------------------------------------- 1 |Here's a code block.
8 | Don't compress this!
9 |
10 | ^ empty line suckas!
11 | What are you going to do about it?
12 | I'm a code block!
13 |
14 | OK.
17 | 18 |This is probably good enough.
19 | 20 |Peace out.
21 | 22 |