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/;
19 gzip
$file => "$file.gz", -Level
=> 9, Minimal
=> 1;
23 my ($file, @content) = @_;
24 write_file
$file, @content;
29 my ($name) = $_[0] =~ m
,/(.*)\
.svg
,;
34 my @logos = <logos
/*>;
35 my $logos = make_sprite \
&sprite_name
, @logos;
38 my $light = s/logos/logos-light/r;
39 push @logos_light, -f
$light ?
$light : $_;
41 my $logos_light = make_sprite \
&sprite_name
, @logos_light;
43 write_gzfile
'static/logos/dark.svg', $logos->render;
44 write_gzfile
'static/logos/light.svg', $logos_light->render;
47 sub read_css_into_blocks
{
50 for (read_file
$file) {
62 $css{common
} .= read_file
$_ for <css
/*.css
>;
64 my (%themes, $rndtheme);
65 for (<css
/themes/*>) {
66 ($rndtheme) = m
,themes
/(.*)\
.css
,;
67 $themes{$rndtheme} = read_css_into_blocks
$_;
70 while (grep { scalar @
$_ } values %themes) {
71 my %blocks = map { $_ => (shift @
{$themes{$_}}) // '' } keys %themes;
72 if (grep { $_ ne $blocks{$rndtheme} } values %blocks) {
73 $css{$_} .= $blocks{$_} for keys %themes;
75 $css{common
} .= $blocks{$rndtheme};
79 write_gzfile
"static/css/$_.css", minify
$css{$_} for keys %css
83 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/*>;
84 my $js = read_file
'static/js/all.js';
85 write_gzfile
'static/js/all.js', '//# sourceMappingURL=/static/js/js.map', "\n", $js;
86 system 'cp', '-rp', 'js', 'static/';
89 my $sprite_mtime = -M
'static/logos/dark.svg' // 0;
90 for (<logos
/*>, <logos-light/*>) {
91 if (!$sprite_mtime || $sprite_mtime > -M
) {
97 my $css_mtime = -M
'static/css/slate.css' // 0;
98 for (<css
/*>, <css
/themes
/*>) {
99 if (!$css_mtime || $css_mtime > -M
) {
105 my $js_mtime = -M
'static/js/all.js' // 0;
107 if (!$js_mtime || $js_mtime > -M
) {
114 my ($file) = m
,(static
.*\
.(?
:css
|js
)),;
116 my $hash = sha256_base64
scalar read_file
$file;
117 s/integrity=".*"/integrity="sha256-$hash="/;