Add fallback and error to minify (#931)

This commit is contained in:
Emi
2024-10-30 15:34:20 -07:00
committed by GitHub
parent c85908fb34
commit 8e923125d4

View File

@@ -7,5 +7,11 @@ Jekyll::Hooks.register :site, :post_write do
Pathname here = Pathname.new(Dir.pwd)
Pathname from = Pathname.new(File.join(Dir.pwd, "_site"))
Pathname to = Pathname.new(Dir.pwd)
`minify -r -o #{to.relative_path_from(here)} #{from.relative_path_from(here)}`
# Attempt to minify using 'minify', fallback to 'gominify' if not present
minify_command = `which minify`.empty? ? 'gominify' : 'minify'
if `which #{minify_command}`.empty?
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