Class: Jekyll::Minify::Minifier
- Inherits:
-
Object
- Object
- Jekyll::Minify::Minifier
- Defined in:
- lib/jekyll-minify.rb
Overview
Minifies HTML, CSS, and JS files in the Jekyll destination directory.
Runs as a Jekyll post-write hook. Processes all eligible files after the site build completes. Files that fail minification are preserved unchanged.
Constant Summary collapse
- DEFAULT_MINIFY_OPTIONS =
Default options passed to the minify-html gem. User overrides from
with_minify_datain _config.yml are merged over these. { keep_html_and_head_opening_tags: true, keep_closing_tags: true, minify_css: true, minify_js: true, remove_bangs: true, remove_processing_instructions: true, ensure_spec_compliant_unquoted_attribute_values: true }.freeze
- ASSET_TYPES =
Asset types processed by the minifier, in order. Each entry has :type (Symbol) and :display_name (String) for logging.
[ { type: :html, display_name: 'HTML' }, { type: :css, display_name: 'CSS' }, { type: :js, display_name: 'JS' } ].freeze
Class Method Summary collapse
-
.minify_site(site) ⇒ void
Minifies all eligible files in the site destination directory.
Instance Method Summary collapse
-
#initialize ⇒ Minifier
constructor
Initializes a new Minifier with empty statistics and a monotonic start time.
-
#run(site) ⇒ Hash?
Runs the minification pipeline for the given site.
Constructor Details
#initialize ⇒ Minifier
Initializes a new Minifier with empty statistics and a monotonic start time.
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/jekyll-minify.rb', line 125 def initialize @minify_options = DEFAULT_MINIFY_OPTIONS @stats = { html: { count: 0, original_bytes: 0, minified_bytes: 0 }, css: { count: 0, original_bytes: 0, minified_bytes: 0 }, js: { count: 0, original_bytes: 0, minified_bytes: 0 }, errors: [] } @start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) end |
Class Method Details
.minify_site(site) ⇒ void
This method returns an undefined value.
Minifies all eligible files in the site destination directory.
140 141 142 |
# File 'lib/jekyll-minify.rb', line 140 def self.minify_site(site) new.run(site) end |
Instance Method Details
#run(site) ⇒ Hash?
Runs the minification pipeline for the given site. Reads configuration from site.config:
- with_minify (Boolean, defaults to true): enable/disable the plugin
- with_minify_data (Hash, optional): override minify-html options
Returns immediately if with_minify is false or the destination directory does not exist.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/jekyll-minify.rb', line 153 def run(site) unless plugin_enabled?(site.config) Jekyll.logger.info 'jekyll-minify:', 'Minification disabled (with_minify: false).' return end @minify_options = (site.config) dest = Pathname.new(site.dest) return unless dest.directory? Jekyll.logger.info 'jekyll-minify:', 'Starting minification...' minify_each_file(dest) log_statistics @stats end |