5 use CSS
::Minifier
::XS qw
/minify/;
6 use Digest
::SHA qw
/sha256_base64/;
7 use IO
::Compress
::Gzip qw
/gzip/;
8 use File
::Slurp qw
/read_file write_file edit_file_lines/;
10 use List
::Util qw
/first/;
18 my $zopfli = which
'zopfli';
19 system $zopfli => $file if $zopfli;
20 gzip
$file => "$file.gz", -Level
=> 9, Minimal
=> 1 unless $zopfli;
24 my ($file, @content) = @_;
25 write_file
$file, @content;
29 sub read_css_into_blocks
{
32 for (read_file
$file) {
44 $css{common
} .= read_file
$_ for <css
/*.css
>;
46 my (%themes, $rndtheme);
47 for (<css
/themes/*>) {
48 ($rndtheme) = m
,themes
/(.*)\
.css
,;
49 $themes{$rndtheme} = read_css_into_blocks
$_;
52 while (grep { scalar @
$_ } values %themes) {
53 my %blocks = map { $_ => (shift @
{$themes{$_}}) // '' } keys %themes;
54 if (grep { $_ ne $blocks{$rndtheme} } values %blocks) {
55 $css{$_} .= $blocks{$_} for keys %themes;
57 $css{common
} .= $blocks{$rndtheme};
61 write_gzfile
"static/css/$_.css", minify
$css{$_} for keys %css
65 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/*>;
66 my $js = read_file
'static/js/all.js';
67 write_gzfile
'static/js/all.js', '//# sourceMappingURL=/static/js/js.map', "\n", $js;
68 system 'cp', '-rp', 'js', 'static/';
71 my $css_mtime = -M
'static/css/slate.css' // 0;
72 for (<css
/*>, <css
/themes
/*>) {
73 if (!$css_mtime || $css_mtime > -M
) {
79 my $js_mtime = -M
'static/js/all.js' // 0;
81 if (!$js_mtime || $js_mtime > -M
) {
88 my ($file) = m
,(static
.*\
.(?
:css
|js
)),;
90 my $hash = sha256_base64
scalar read_file
$file;
91 s/integrity=".*"/integrity="sha256-$hash="/;