diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Makefile | 20 | ||||
-rw-r--r-- | data/style.css | 2 | ||||
-rwxr-xr-x | util/skingen.pl | 27 |
4 files changed, 28 insertions, 24 deletions
@@ -13,7 +13,8 @@ /static/f/vndb.js.gz /static/feeds/ /static/s/*/style.css -/static/s/*/style.css.gz +/static/s/*/style.min.css +/static/s/*/style.min.css.gz /static/s/*/boxbg.png /static/v3/elm.js /static/v3/elm-opt.js @@ -2,7 +2,10 @@ # Create all the necessary directories, javascript, css, etc. # # prod -# Create static assets for production (v3 only). +# Create static assets for production. Requires the following additional dependencies: +# - CSS::Minifier::XS +# - uglifyjs +# - zopfli # # chmod # For when the http process is run from a different user than the files are @@ -36,7 +39,9 @@ ALL_CLEAN=\ PROD=\ static/v3/elm-opt.js \ static/v3/min.js static/v3/min.js.gz \ - static/v3/min.css static/v3/min.css.gz + static/v3/min.css static/v3/min.css.gz \ + $(shell ls static/s | sed -e 's/\(.\+\)/static\/s\/\1\/style.min.css/g') \ + $(shell ls static/s | sed -e 's/\(.\+\)/static\/s\/\1\/style.min.css.gz/g') all: ${ALL_KEEP} ${ALL_CLEAN} prod: ${PROD} @@ -44,7 +49,6 @@ prod: ${PROD} clean: rm -f ${ALL_CLEAN} ${PROD} rm -f static/f/icons.png - rm -f static/s/*/style.css.gz static/s/*/boxbg.png rm -f elm3/Lib/Gen.elm rm -rf elm3/elm-stuff/build-artifacts @@ -80,6 +84,12 @@ data/icons/icons.css: data/icons/*.png data/icons/*/*.png util/spritegen.pl | st static/s/%/style.css: static/s/%/conf util/skingen.pl data/style.css data/icons/icons.css util/skingen.pl $* +static/s/%/style.min.css: static/s/%/style.css + perl -MCSS::Minifier::XS -e 'undef $$/; print CSS::Minifier::XS::minify(scalar <>)' <$< >$@ + +static/s/%/style.min.css.gz: static/s/%/style.min.css + zopfli $< + elm3/Lib/Gen.elm: lib/VN3/*.pm lib/VN3/*/*.pm data/config3.pl util/vndb3.pl elmgen >$@ @@ -88,7 +98,7 @@ static/v3/elm.js: elm3/*.elm elm3/*/*.elm elm3/Lib/Gen.elm | static/f sed -i 's/var author\$$project\$$Lib\$$Ffi\$$/var __unused__/g' $@ sed -Ei 's/author\$$project\$$Lib\$$Ffi\$$([a-zA-Z0-9_]+)/window.elmFfi_\1(_Json_wrap)/g' $@ -static/v3/elm-opt.js: elm/*.elm elm/*/*.elm elm/Lib/Gen.elm | static/f +static/v3/elm-opt.js: elm3/*.elm elm3/*/*.elm elm3/Lib/Gen.elm | static/f cd elm3 && ELM_HOME=elm-stuff elm make --optimize *.elm */*.elm --output ../$@ sed -i 's/var author\$$project\$$Lib\$$Ffi\$$/var __unused__/g' $@ sed -Ei 's/author\$$project\$$Lib\$$Ffi\$$([a-zA-Z0-9_]+)/window.elmFfi_\1(_Json_wrap)/g' $@ @@ -111,7 +121,7 @@ static/v3/style.css: ${CSS} | static/f cat $^ >$@ static/v3/min.css: static/v3/style.css - uglifycss $^ >$@ + perl -MCSS::Minifier::XS -e 'undef $$/; print CSS::Minifier::XS::minify(scalar <>)' <$< >$@ static/v3/min.css.gz: static/v3/min.css zopfli $< diff --git a/data/style.css b/data/style.css index 57cbbd30..e4684d53 100644 --- a/data/style.css +++ b/data/style.css @@ -959,7 +959,7 @@ p.filselect i { font-style: normal } /****** Icons *******/ .icons { - background: url(/f/icons.png?$version$) no-repeat; + background: url(/f/icons.png?$icons_version$) no-repeat; width: 16px; height: 14px; margin: 0 2px 0 0; diff --git a/util/skingen.pl b/util/skingen.pl index 7ed5f47e..8d9f3b4e 100755 --- a/util/skingen.pl +++ b/util/skingen.pl @@ -1,11 +1,8 @@ #!/usr/bin/perl -package VNDB; - -use strict; +use v5.12; use warnings; use Cwd 'abs_path'; -eval { require CSS::Minifier::XS }; our($ROOT, %S); BEGIN { ($ROOT = abs_path $0) =~ s{/util/skingen\.pl$}{}; } @@ -13,8 +10,6 @@ BEGIN { ($ROOT = abs_path $0) =~ s{/util/skingen\.pl$}{}; } use lib "$ROOT/lib"; use SkinFile; -require $ROOT.'/data/global.pl'; - my $iconcss = do { open my $F, '<', "$ROOT/data/icons/icons.css" or die $!; @@ -49,6 +44,8 @@ sub blend { ($f[2] * $f[3] + $b[2] * (1 - $f[3]))*255; } +sub mtime($) { [stat("$ROOT/static$_[0]")]->[9] } + sub writeskin { # $name my $name = shift; @@ -60,14 +57,15 @@ sub writeskin { # $name 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, $S{version}, $w, $h; + $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}) { - $o{_bodybg} = sprintf 'background: %s url(/s/%s/%s?%s) no-repeat', $o{bodybg}, $name, $o{imglefttop}, $S{version}; + 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}; } @@ -76,25 +74,20 @@ sub writeskin { # $name $o{_blendbg} = blend $o{boxbg}, $o{bodybg}; # version - $o{version} = $S{version}; + $o{icons_version} = mtime '/f/icons.png'; # write the CSS open my $CSS, '<', "$ROOT/data/style.css" or die $!; - my $css = join '', <$CSS>; + local $/=undef; + my $css = <$CSS>; close $CSS; - $css =~ s/\$$_\$/$o{$_}/g for (keys %o); my $f = "$ROOT/static/s/$name/style.css"; open my $SKIN, '>', "$f~" or die $!; - print $SKIN $CSS::Minifier::XS::VERSION ? CSS::Minifier::XS::minify($css) : $css; + print $SKIN $css =~ s{\$([a-z_]+)\$}{$o{$1} // die "Unknown variable $1"}egr; close $SKIN; rename "$f~", $f; - - if($VNDB::SKINGEN{gzip}) { - `$VNDB::SKINGEN{gzip} -c '$f' >'$f.gz~'`; - rename "$f.gz~", "$f.gz"; - } } |