-
-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathminify-assets.rb
More file actions
19 lines (18 loc) · 714 Bytes
/
minify-assets.rb
File metadata and controls
19 lines (18 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
require 'pathname'
# Minify assets after each build
Jekyll::Hooks.register :site, :post_write do
puts "Minifying assets"
# Project path
Pathname here = Pathname.new(Dir.pwd)
Pathname from = Pathname.new(File.join(Dir.pwd, "_site"))
Pathname to = Pathname.new(Dir.pwd)
# Attempt to minify using 'minify', fallback to 'gominify' if not present
`sh -c 'command -v minify'`
minify_command = $?.exitstatus != 0 ? 'gominify' : 'minify'
`sh -c 'command -v #{minify_command}'`
if $?.exitstatus != 0
puts "ERROR: Neither 'minify' nor 'gominify' is installed. Please install 'minify'."
exit 1
end
`#{minify_command} -r -o #{to.relative_path_from(here)} #{from.relative_path_from(here)}`
end