X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=make_static.PL;fp=make_static.PL;h=23c5643d91ddeb063d4b0236890fd38856af593a;hb=b8d36f0686c49a0220cc4c1ef59e47759f7a10f8;hp=0c4396036d0fc6c4805a89685ef1b175f7bf1173;hpb=5eae1f77a18ef8273f3a0cd6d4af8c19a4986880;p=gruntmaster-page.git diff --git a/make_static.PL b/make_static.PL index 0c43960..23c5643 100644 --- a/make_static.PL +++ b/make_static.PL @@ -3,6 +3,7 @@ use v5.14; use warnings; use CSS::Minifier::XS qw/minify/; +use CSS::SpriteMaker; use Digest::SHA qw/sha256_base64/; use IO::Compress::Gzip qw/gzip/; use File::Slurp qw/read_file write_file edit_file_lines/; @@ -12,6 +13,31 @@ mkdir 'static'; mkdir 'static/css'; 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; @@ -63,6 +89,14 @@ sub make_js { gzip_file 'static/js/all.js'; } +my $sprite_mtime = -M 'static/logos.png' // 0; +for () { + if (!$sprite_mtime || $sprite_mtime > -M) { + make_sprite; + last + } +} + my $css_mtime = -M 'static/css/slate.css' // 0; for (, ) { if (!$css_mtime || $css_mtime > -M) { @@ -84,4 +118,25 @@ edit_file_lines { return unless $file; my $hash = sha256_base64 scalar read_file $file; s/integrity=".*"/integrity="sha256-$hash="/; -} 'tmpl/skel.en' +} 'tmpl/skel.en'; + +package + Local::CSS::SpriteMaker; + +use parent qw/CSS::SpriteMaker/; + +sub _get_stylesheet_string { + my $self = shift; + my @ret = split "\n", $self->SUPER::_get_stylesheet_string(@_); + shift @ret; + @ret = sort @ret; + unshift @ret, <