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) = @_;
- gzip $file => "$file.gz", -Level => 9, Minimal => 1;
+ my $zopfli = which 'zopfli';
+ system $zopfli => $file if $zopfli;
+ gzip $file => "$file.gz", -Level => 9, Minimal => 1 unless $zopfli;
}
sub write_gzfile {
gzip_file $file
}
+sub sprite_name {
+ my ($name) = $_[0] =~ m,/(.*)\.svg,;
+ "logo-$name"
+}
+
+sub make_logos {
+ my @logos = <logos/*>;
+ my $logos = make_sprite \&sprite_name, @logos;
+ my @logos_light;
+ for (<logos/*>) {
+ 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);
system 'cp', '-rp', 'js', 'static/';
}
+my $sprite_mtime = -M 'static/logos/dark.svg' // 0;
+for (<logos/*>, <logos-light/*>) {
+ if (!$sprite_mtime || $sprite_mtime > -M) {
+ make_logos;
+ last
+ }
+}
+
my $css_mtime = -M 'static/css/slate.css' // 0;
for (<css/*>, <css/themes/*>) {
if (!$css_mtime || $css_mtime > -M) {
return unless $file;
my $hash = sha256_base64 scalar read_file $file;
s/integrity=".*"/integrity="sha256-$hash="/;
-} 'tmpl/skel.en'
+} 'tmpl/skel.en';