Skip to content

Commit 406408f

Browse files
Merge pull request #23 from chris-huxtable/htmlcompressor-options
Htmlcompressor options
2 parents 1857c31 + 1bcfc98 commit 406408f

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,27 @@ Optionally, you can also add exclusions using:
2020
<pre><code>jekyll-minifier:
2121
exclude: 'atom.xml' # Exclude files from processing - file name, glob pattern or array of file names and glob patterns
2222
</code></pre>
23+
and toggle htmlcompressor features using:
24+
<pre><code>jekyll-minifier:
25+
preserve_php: true # Default: false
26+
remove_spaces_inside_tags: true # Default: true
27+
remove_multi_spaces: true # Default: true
28+
remove_comments: true # Default: true
29+
remove_intertag_spaces: true # Default: false
30+
remove_quotes: false # Default: false
31+
compress_css: true # Default: true
32+
compress_javascript: true # Default: true
33+
simple_doctype: false # Default: false
34+
remove_script_attributes: false # Default: false
35+
remove_style_attributes: false # Default: false
36+
remove_link_attributes: false # Default: false
37+
remove_form_attributes: false # Default: false
38+
remove_input_attributes: false # Default: false
39+
remove_javascript_protocol: false # Default: false
40+
remove_http_protocol: false # Default: false
41+
remove_https_protocol: false # Default: false
42+
preserve_line_breaks: false # Default: false
43+
simple_boolean_attributes: false # Default: false
44+
compress_js_templates: false # Default: false
45+
</code></pre>
2346

lib/jekyll-minifier.rb

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,42 @@ def output_file(dest, content)
3030
end
3131

3232
def output_html(path, content)
33-
compressor = HtmlCompressor::Compressor.new({ :remove_comments => true, :compress_css => true, :compress_javascript => true, :css_compressor => CSSminify2.new, :javascript_compressor => Uglifier.new })
33+
args = { remove_comments: true, compress_css: true, compress_javascript: true, preserve_patterns: [] }
34+
args[:css_compressor] = CSSminify2.new
35+
args[:javascript_compressor] = Uglifier.new
36+
37+
opts = @site.config['jekyll-minifier']
38+
39+
if ( !opts.nil? )
40+
# Convert keys to symboles
41+
opts.keys.each { |key| opts[(key.to_sym rescue key) || key] = opts.delete(key) }
42+
43+
args[:remove_spaces_inside_tags] = opts[:remove_spaces_inside_tags] if opts.has_key?(:remove_spaces_inside_tags)
44+
args[:remove_multi_spaces] = opts[:remove_multi_spaces] if opts.has_key?(:remove_multi_spaces)
45+
args[:remove_comments] = opts[:remove_comments] if opts.has_key?(:remove_comments)
46+
args[:remove_intertag_spaces] = opts[:remove_intertag_spaces] if opts.has_key?(:remove_intertag_spaces)
47+
args[:remove_quotes] = opts[:remove_quotes] if opts.has_key?(:remove_quotes)
48+
args[:compress_css] = opts[:compress_css] if opts.has_key?(:compress_css)
49+
args[:compress_javascript] = opts[:compress_javascript] if opts.has_key?(:compress_javascript)
50+
args[:simple_doctype] = opts[:simple_doctype] if opts.has_key?(:simple_doctype)
51+
args[:remove_script_attributes] = opts[:remove_script_attributes] if opts.has_key?(:remove_script_attributes)
52+
args[:remove_style_attributes] = opts[:remove_style_attributes] if opts.has_key?(:remove_style_attributes)
53+
args[:remove_link_attributes] = opts[:remove_link_attributes] if opts.has_key?(:remove_link_attributes)
54+
args[:remove_form_attributes] = opts[:remove_form_attributes] if opts.has_key?(:remove_form_attributes)
55+
args[:remove_input_attributes] = opts[:remove_input_attributes] if opts.has_key?(:remove_input_attributes)
56+
args[:remove_javascript_protocol] = opts[:remove_javascript_protocol] if opts.has_key?(:remove_javascript_protocol)
57+
args[:remove_http_protocol] = opts[:remove_http_protocol] if opts.has_key?(:remove_http_protocol)
58+
args[:remove_https_protocol] = opts[:remove_https_protocol] if opts.has_key?(:remove_https_protocol)
59+
args[:preserve_line_breaks] = opts[:preserve_line_breaks] if opts.has_key?(:preserve_line_breaks)
60+
args[:simple_boolean_attributes] = opts[:simple_boolean_attributes] if opts.has_key?(:simple_boolean_attributes)
61+
args[:compress_js_templates] = opts[:compress_js_templates] if opts.has_key?(:compress_js_templates)
62+
args[:preserve_patterns] += [/<\?php.*?\?>/im] if opts[:preserve_php] == true
63+
64+
# Potential to add patterns from YAML
65+
#args[:preserve_patterns] += opts[:preserve_patterns].map { |pattern| Regexp.new(pattern)} if opts.has_key?(:preserve_patterns)
66+
end
67+
68+
compressor = HtmlCompressor::Compressor.new(args)
3469
output_file(path, compressor.compress(content))
3570
end
3671

lib/jekyll-minifier/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Jekyll
22
module Minifier
3-
VERSION = "0.1.1"
3+
VERSION = "0.1.2"
44
end
55
end

0 commit comments

Comments
 (0)