5 use CSS
::Minifier
::XS qw
/minify/;
7 use Digest
::SHA qw
/sha256_base64/;
8 use IO
::Compress
::Gzip qw
/gzip/;
9 use File
::Slurp qw
/read_file write_file edit_file_lines/;
10 use List
::Util qw
/first/;
17 my $maker = Local
::CSS
::SpriteMaker
->new(
18 css_class_prefix
=> 'logo-',
19 rc_override_classname
=> sub {
21 $name =~ s/-light/.logo-light/r;
26 source_images
=> ['logos/'],
27 target_file
=> 'static/logos.png',
28 add_extra_padding
=> 10,
32 filename
=> 'css/logos.css',
33 sprite_filename
=> '/static/logos.png',
36 system 'pngnq-s9', '-s1', 'static/logos.png';
37 system 'optipng', '-o7', '-zm1-9', 'static/logos-nq8.png';
38 rename 'static/logos-nq8.png', 'static/logos.png';
43 gzip
$file => "$file.gz", -Level
=> 9, Minimal
=> 1;
46 sub read_css_into_blocks
{
49 for (read_file
$file) {
61 $css{common
} .= read_file
$_ for <css
/*.css
>;
63 my (%themes, $rndtheme);
64 for (<css
/themes/*>) {
65 ($rndtheme) = m
,themes
/(.*)\
.css
,;
66 $themes{$rndtheme} = read_css_into_blocks
$_;
69 while (grep { scalar @
$_ } values %themes) {
70 my %blocks = map { $_ => (shift @
{$themes{$_}}) // '' } keys %themes;
71 if (grep { $_ ne $blocks{$rndtheme} } values %blocks) {
72 $css{$_} .= $blocks{$_} for keys %themes;
74 $css{common
} .= $blocks{$rndtheme};
78 for my $name (keys %css) {
79 write_file
"static/css/$name.css", minify
$css{$name};
80 gzip_file
"static/css/$name.css"
85 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/*>;
86 my $js = read_file
'static/js/all.js';
87 write_file
'static/js/all.js', '//# sourceMappingURL=/static/js/js.map', "\n", $js;
88 system 'cp', '-rp', 'js', 'static/';
89 gzip_file
'static/js/all.js';
92 my $sprite_mtime = -M
'static/logos.png' // 0;
94 if (!$sprite_mtime || $sprite_mtime > -M
) {
100 my $css_mtime = -M
'static/css/slate.css' // 0;
101 for (<css
/*>, <css
/themes
/*>) {
102 if (!$css_mtime || $css_mtime > -M
) {
108 my $js_mtime = -M
'static/js/all.js' // 0;
110 if (!$js_mtime || $js_mtime > -M
) {
117 my ($file) = m
,(static
.*\
.(?
:css
|js
)),;
119 my $hash = sha256_base64
scalar read_file
$file;
120 s/integrity=".*"/integrity="sha256-$hash="/;
124 Local
::CSS
::SpriteMaker
;
126 use parent qw
/CSS::SpriteMaker/;
128 sub _get_stylesheet_string
{
130 my @ret = split "\n", $self->SUPER::_get_stylesheet_string
(@_);
135 background-image: url("/static/logos.png");
136 background-repeat: no-repeat;
137 display: inline-block;
138 vertical-align: middle;