+mkdir 'static/js';
+
+sub make_sprite {
+ my $maker = Local::CSS::SpriteMaker->new(
+ css_class_prefix => 'logo-',
+ rc_override_classname => sub {
+ my ($name) = @_;
+ $name =~ s/-light/.logo-light/r;
+ }
+ );
+
+ $maker->make_sprite(
+ source_images => ['logos/'],
+ target_file => 'static/logos.png',
+ add_extra_padding => 10,
+ );
+
+ $maker->print_css(
+ filename => 'css/logos.css',
+ sprite_filename => '/static/logos.png',
+ );
+
+ system 'pngnq-s9', '-s1', 'static/logos.png';
+ system 'optipng', '-o7', '-zm1-9', 'static/logos-nq8.png';
+ rename 'static/logos-nq8.png', 'static/logos.png';
+}
+
+sub gzip_file {
+ my ($file) = @_;
+ gzip $file => "$file.gz", -Level => 9, Minimal => 1;
+}
+
+sub read_css_into_blocks {
+ my ($file) = @_;
+ my (@blocks, $block);
+ for (read_file $file) {
+ $block .= $_;
+ if (/^}/) {
+ push @blocks, $block;
+ $block = '';
+ }
+ }
+ \@blocks
+}
+
+sub make_css {
+ my %css;
+ $css{common} .= read_file $_ for <css/*.css>;
+
+ my (%themes, $rndtheme);
+ for (<css/themes/*>) {
+ ($rndtheme) = m,themes/(.*)\.css,;
+ $themes{$rndtheme} = read_css_into_blocks $_;
+ }
+
+ while (grep { scalar @$_ } values %themes) {
+ my %blocks = map { $_ => (shift @{$themes{$_}}) // '' } keys %themes;
+ if (grep { $_ ne $blocks{$rndtheme} } values %blocks) {
+ $css{$_} .= $blocks{$_} for keys %themes;
+ } else {
+ $css{common} .= $blocks{$rndtheme};
+ }
+ }