Add `jekyll-minifier` (#668)
* Remove obsolete plugins * Add `jekyll-minifier` * Add `JEKYLL_ENV=production`
This commit is contained in:
parent
e40bc98f47
commit
503bfc235a
5
Gemfile
5
Gemfile
|
|
@ -5,18 +5,17 @@ group :jekyll_plugins do
|
||||||
gem 'jekyll-diagrams'
|
gem 'jekyll-diagrams'
|
||||||
gem 'jekyll-email-protect'
|
gem 'jekyll-email-protect'
|
||||||
gem 'jekyll-feed'
|
gem 'jekyll-feed'
|
||||||
gem 'jekyll-github-metadata'
|
|
||||||
gem 'jekyll-imagemagick'
|
gem 'jekyll-imagemagick'
|
||||||
|
gem 'jekyll-minifier'
|
||||||
gem 'jekyll-paginate-v2'
|
gem 'jekyll-paginate-v2'
|
||||||
gem 'jekyll-scholar'
|
gem 'jekyll-scholar'
|
||||||
gem 'jekyll-sitemap'
|
gem 'jekyll-sitemap'
|
||||||
gem 'jekyll-target-blank'
|
gem 'jekyll-target-blank'
|
||||||
gem 'jekyll-twitter-plugin'
|
gem 'jekyll-twitter-plugin'
|
||||||
gem 'jemoji'
|
gem 'jemoji'
|
||||||
|
gem 'mini_racer'
|
||||||
gem 'unicode_utils'
|
gem 'unicode_utils'
|
||||||
gem 'webrick'
|
gem 'webrick'
|
||||||
gem 'htmlcompressor'
|
|
||||||
gem 'htmlbeautifier'
|
|
||||||
end
|
end
|
||||||
group :other_plugins do
|
group :other_plugins do
|
||||||
gem 'httparty'
|
gem 'httparty'
|
||||||
|
|
|
||||||
24
_config.yml
24
_config.yml
|
|
@ -156,8 +156,8 @@ plugins:
|
||||||
- jekyll-diagrams
|
- jekyll-diagrams
|
||||||
- jekyll-email-protect
|
- jekyll-email-protect
|
||||||
- jekyll-feed
|
- jekyll-feed
|
||||||
- jekyll-github-metadata
|
|
||||||
- jekyll-imagemagick
|
- jekyll-imagemagick
|
||||||
|
- jekyll-minifier
|
||||||
- jekyll-paginate-v2
|
- jekyll-paginate-v2
|
||||||
- jekyll/scholar
|
- jekyll/scholar
|
||||||
- jekyll-sitemap
|
- jekyll-sitemap
|
||||||
|
|
@ -171,27 +171,15 @@ defaults:
|
||||||
path: "assets/**/*.*"
|
path: "assets/**/*.*"
|
||||||
values:
|
values:
|
||||||
sitemap: false
|
sitemap: false
|
||||||
# Extras
|
|
||||||
github: [metadata]
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# Jekyll optimization
|
# Jekyll Minifier
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
# HTML remove comments (<!-- .... -->)
|
jekyll-minifier:
|
||||||
remove_HTML_comments: false
|
exclude: ['robots.txt']
|
||||||
|
uglifier_args:
|
||||||
# HTML beautifier (_plugins/beautify.rb).
|
harmony: true
|
||||||
# Source: https://github.com/threedaymonk/htmlbeautifier
|
|
||||||
beautify: false # This function has conflict with the code snippets, they can be displayed incorrectly
|
|
||||||
|
|
||||||
# HTML minify (_plugins/minify.rb).
|
|
||||||
# Source: https://www.ffbit.com/blog/2021/03/17/html-minification-in-jekyll.html
|
|
||||||
minify: false
|
|
||||||
|
|
||||||
# CSS/SASS minify
|
|
||||||
sass:
|
|
||||||
style: compressed
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# Jekyll Archives
|
# Jekyll Archives
|
||||||
|
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
require 'htmlbeautifier'
|
|
||||||
|
|
||||||
module Jekyll
|
|
||||||
module StripHTML
|
|
||||||
def beautify(content)
|
|
||||||
if beautify_enabled?
|
|
||||||
content = HtmlBeautifier.beautify(content)
|
|
||||||
else
|
|
||||||
content
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def beautify_enabled?
|
|
||||||
config = @context.registers[:site].config
|
|
||||||
true?(config['beautify'])
|
|
||||||
end
|
|
||||||
|
|
||||||
def true?(obj)
|
|
||||||
obj.to_s.downcase == 'true'
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Liquid::Template.register_filter(Jekyll::StripHTML)
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
# Source: https://www.ffbit.com/blog/2021/03/17/html-minification-in-jekyll.html
|
|
||||||
require 'htmlcompressor'
|
|
||||||
|
|
||||||
module Jekyll
|
|
||||||
module MinifyFilter
|
|
||||||
def minify(content)
|
|
||||||
if minify_enabled?
|
|
||||||
compressor = HtmlCompressor::Compressor.new
|
|
||||||
compressor.compress content
|
|
||||||
else
|
|
||||||
content
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def minify_enabled?
|
|
||||||
config = @context.registers[:site].config
|
|
||||||
true?(config['minify'])
|
|
||||||
end
|
|
||||||
|
|
||||||
def true?(obj)
|
|
||||||
obj.to_s.downcase == 'true'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Liquid::Template.register_filter(Jekyll::MinifyFilter)
|
|
||||||
|
|
@ -91,6 +91,9 @@ then
|
||||||
fi
|
fi
|
||||||
git checkout -b $DEPLOY_BRANCH
|
git checkout -b $DEPLOY_BRANCH
|
||||||
|
|
||||||
|
# Export JEKYLL_ENV=production
|
||||||
|
export JEKYLL_ENV=production
|
||||||
|
|
||||||
# Build site
|
# Build site
|
||||||
bundle exec jekyll build
|
bundle exec jekyll build
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue