diff options
author | Yorhel <git@yorhel.nl> | 2021-01-17 10:49:57 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2021-01-17 14:01:47 +0100 |
commit | 692ef20253a202d4eeb04d4a6491669dc6c30cb5 (patch) | |
tree | 6c55208710bdb0b422da090fa722768b42b39f64 /util | |
parent | c940802c172654efa6669cf2ff3161c8588f15b0 (diff) |
Use SASS for CSS + static asset reoganization
Had been planning to use a more powerful preprocessor for CSS for a
while, so that I can also reorganize and clean up the CSS a bit. The
cleanup will come later, this is the first step to reorganize the build
system a bit and remove skingen.pl.
I moved all generated static assets to static/g/ (for _g_enerated),
including icons.png and js files. This simplifies management of
static/f/ and static/s/, which are fully in git.
Skins are now defined as sass files in css/skins/ with their images in
static/s/ using plain directory structure.
Diffstat (limited to 'util')
-rwxr-xr-x | util/jsgen.pl | 2 | ||||
-rwxr-xr-x | util/skingen.pl | 99 | ||||
-rwxr-xr-x | util/spritegen.pl | 4 |
3 files changed, 3 insertions, 102 deletions
diff --git a/util/jsgen.pl b/util/jsgen.pl index 84a5c8f1..a4023ff8 100755 --- a/util/jsgen.pl +++ b/util/jsgen.pl @@ -59,4 +59,4 @@ sub save { my $js = readjs; $js =~ s{/\*VARS\*/}{vars()}eg; -save "$ROOT/static/f/vndb.js", $js; +save "$ROOT/static/g/vndb.js", $js; diff --git a/util/skingen.pl b/util/skingen.pl deleted file mode 100755 index 2114b7fc..00000000 --- a/util/skingen.pl +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/perl - -use v5.12; -use warnings; -use Cwd 'abs_path'; - -our($ROOT, %S); -BEGIN { ($ROOT = abs_path $0) =~ s{/util/skingen\.pl$}{}; } - -use lib "$ROOT/lib"; -use VNDB::Skins; - - -my $iconcss = do { - open my $F, '<', "$ROOT/data/icons/icons.css" or die $!; - local $/=undef; - <$F>; -}; - - -sub imgsize { - open my $IMG, '<', $_[0] or die $!; - sysread $IMG, my $buf, 1024 or die $!; - $buf =~ /\xFF\xC0...(....)/s ? unpack('nn', $1) : $buf =~ /IHDR(.{8})/s ? unpack('NN', $1) : die; -} - - -sub rdcolor { - length $_[0] == 4 ? map hex($_)/15, $_[0] =~ /#(.)(.)(.)/ : #RGB - length $_[0] == 7 ? map hex($_)/255, $_[0] =~ /#(..)(..)(..)/ : #RRGGBB - length $_[0] == 9 ? map hex($_)/255, $_[0] =~ /#(..)(..)(..)(..)/ : #RRGGBBAA - die; -} - - -sub blend { - my($f, $b) = @_; - my @f = rdcolor $f; - my @b = rdcolor $b; - $f[3] //= 1; - sprintf '#%02x%02x%02x', - ($f[0] * $f[3] + $b[0] * (1 - $f[3]))*255, - ($f[1] * $f[3] + $b[1] * (1 - $f[3]))*255, - ($f[2] * $f[3] + $b[2] * (1 - $f[3]))*255; -} - -sub mtime($) { [stat("$ROOT/static$_[0]")]->[9] } - - -sub writeskin { # $name - my $name = shift; - my %o = skins->{$name}->%*; - $o{iconcss} = $iconcss; - - # get the right top image - if($o{imgrighttop}) { - my $path = "/s/$name/$o{imgrighttop}"; - my($h, $w) = imgsize "$ROOT/static$path"; - $o{_bgright} = sprintf 'background: url(%s?%s) no-repeat; width: %dpx; height: %dpx', $path, mtime $path, $w, $h; - } else { - $o{_bgright} = 'display: none'; - } - - # body background - if($o{imglefttop}) { - my $path = "/s/$name/$o{imglefttop}"; - $o{_bodybg} = sprintf 'background: %s url(%s?%s) no-repeat', $o{bodybg}, $path, mtime $path; - } else { - $o{_bodybg} = sprintf 'background-color: %s', $o{bodybg}; - } - - # boxbg blended with bodybg - $o{_blendbg} = blend $o{boxbg}, $o{bodybg}; - - # version - $o{icons_version} = mtime '/f/icons.png'; - - # write the CSS - open my $CSS, '<', "$ROOT/data/style.css" or die $!; - local $/=undef; - my $css = <$CSS>; - close $CSS; - - my $f = "$ROOT/static/s/$name/style.css"; - open my $SKIN, '>', "$f~" or die $!; - print $SKIN $css =~ s{\$([a-z_]+)\$}{$o{$1} // die "Unknown variable $1"}egr; - close $SKIN; - - rename "$f~", $f; -} - - -if(@ARGV) { - writeskin($_) for (@ARGV); -} else { - writeskin($_) for (keys skins->%*); -} - - diff --git a/util/spritegen.pl b/util/spritegen.pl index e88af5ce..c2644883 100755 --- a/util/spritegen.pl +++ b/util/spritegen.pl @@ -11,8 +11,8 @@ use lib "$ROOT/lib"; use VNDB::Config; my $path = "$ROOT/data/icons"; -my $icons = "$ROOT/static/f/icons.png"; -my $ticons = "$ROOT/static/f/icons~.png"; +my $icons = "$ROOT/static/g/icons.png"; +my $ticons = "$ROOT/static/g/icons~.png"; my $css = "$ROOT/data/icons/icons.css"; my @img = map { |