X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=make_static.PL;h=77ab59f894e590dfbadf9bb3626a970f94c0abd3;hb=refs%2Fheads%2Fnewmc;hp=f599a56b5db514f6b15e87a1e9ae71b89d4afa2b;hpb=db73dc0cea19c7992776392125cd49e28014ea81;p=gruntmaster-page.git diff --git a/make_static.PL b/make_static.PL index f599a56..77ab59f 100644 --- a/make_static.PL +++ b/make_static.PL @@ -6,16 +6,20 @@ use CSS::Minifier::XS qw/minify/; use Digest::SHA qw/sha256_base64/; use IO::Compress::Gzip qw/gzip/; use File::Slurp qw/read_file write_file edit_file_lines/; +use SVG::SpriteMaker; use File::Which; use List::Util qw/first/; mkdir 'static'; mkdir 'static/css'; mkdir 'static/js'; +mkdir 'static/logos'; sub gzip_file { my ($file) = @_; + my $brotli = which 'brotli'; my $zopfli = which 'zopfli'; + system $brotli => '--input', $file, '--output', "$file.br" if $brotli; system $zopfli => $file if $zopfli; gzip $file => "$file.gz", -Level => 9, Minimal => 1 unless $zopfli; } @@ -26,6 +30,25 @@ sub write_gzfile { gzip_file $file } +sub sprite_name { + my ($name) = $_[0] =~ m,/(.*)\.svg,; + "logo-$name" +} + +sub make_logos { + my @logos = ; + my $logos = make_sprite \&sprite_name, @logos; + my @logos_light; + for () { + my $light = s/logos/logos-light/r; + push @logos_light, -f $light ? $light : $_; + } + my $logos_light = make_sprite \&sprite_name, @logos_light; + + write_gzfile 'static/logos/dark.svg', $logos->render; + write_gzfile 'static/logos/light.svg', $logos_light->render; +} + sub read_css_into_blocks { my ($file) = @_; my (@blocks, $block); @@ -85,6 +108,14 @@ sub make_js { system 'cp', '-rp', 'js', 'static/'; } +my $sprite_mtime = -M 'static/logos/dark.svg' // 0; +for (, ) { + if (!$sprite_mtime || $sprite_mtime > -M) { + make_logos; + last + } +} + my $css_mtime = -M 'static/css/all.css' // 0; for (, ) { if (!$css_mtime || $css_mtime > -M) { @@ -106,4 +137,4 @@ 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';