use Digest::SHA qw/sha256_base64/;
use IO::Compress::Gzip qw/gzip/;
use File::Slurp qw/read_file write_file edit_file_lines/;
+use File::Which;
use List::Util qw/first/;
mkdir 'static';
sub gzip_file {
my ($file) = @_;
- gzip $file => "$file.gz", -Level => 9, Minimal => 1;
+ my $zopfli = which 'zopfli';
+ system $zopfli => $file if $zopfli;
+ gzip $file => "$file.gz", -Level => 9, Minimal => 1 unless $zopfli;
+}
+
+sub write_gzfile {
+ my ($file, @content) = @_;
+ write_file $file, @content;
+ gzip_file $file
}
sub read_css_into_blocks {
}
}
- for my $name (keys %css) {
- write_file "static/css/$name.css", minify $css{$name};
- gzip_file "static/css/$name.css"
- }
+ write_gzfile "static/css/$_.css", minify $css{$_} for keys %css
}
sub make_js {
system java => -jar => 'compiler.jar', qw,-O SIMPLE --create_source_map static/js/js.map --js_output_file static/js/all.js --language_in ECMASCRIPT6_STRICT --language_out ECMASCRIPT5_STRICT --source_map_location_mapping js/|/static/js/,, <js/*>;
my $js = read_file 'static/js/all.js';
- write_file 'static/js/all.js', '//# sourceMappingURL=/static/js/js.map', "\n", $js;
+ write_gzfile 'static/js/all.js', '//# sourceMappingURL=/static/js/js.map', "\n", $js;
system 'cp', '-rp', 'js', 'static/';
- gzip_file 'static/js/all.js';
}
my $css_mtime = -M 'static/css/slate.css' // 0;