]>
Commit | Line | Data |
---|---|---|
8798626b MG |
1 | #!/usr/bin/perl |
2 | use v5.14; | |
3 | use warnings; | |
4 | ||
5 | use CSS::Minifier::XS qw//; | |
6eb2623e | 6 | use CSS::SpriteMaker; |
8798626b MG |
7 | use JavaScript::Minifier::XS qw//; |
8 | ||
9 | use File::Slurp qw/read_file write_file/; | |
10 | ||
11 | mkdir 'static'; | |
12 | mkdir 'static/css'; | |
13 | ||
69d77267 MG |
14 | sub make_sprite { |
15 | my $maker = Local::CSS::SpriteMaker->new( | |
16 | css_class_prefix => 'logo-', | |
17 | rc_override_classname => sub { | |
18 | my ($name) = @_; | |
19 | $name =~ s/-light/.logo-light/r; | |
20 | } | |
21 | ); | |
6eb2623e | 22 | |
69d77267 MG |
23 | $maker->make_sprite( |
24 | source_images => ['logos/'], | |
25 | target_file => 'static/logos.png', | |
26 | add_extra_padding => 10, | |
27 | ); | |
6eb2623e | 28 | |
69d77267 MG |
29 | $maker->print_css( |
30 | filename => 'css/logos.css', | |
31 | sprite_filename => 'https://static.mindcoding.ro/static/logos.png', | |
32 | ); | |
6eb2623e | 33 | |
0e8866c3 MG |
34 | system 'pngnq-s9', '-s1', 'static/logos.png'; |
35 | system 'optipng', '-o7', '-zm1-9', 'static/logos-nq8.png'; | |
36 | rename 'static/logos-nq8.png', 'static/logos.png'; | |
69d77267 | 37 | } |
c9dee865 | 38 | |
cf2b0139 MG |
39 | sub make_css { |
40 | my $common_css; | |
41 | $common_css .= read_file $_ for <css/*.css>; | |
42 | for (<css/themes/*>) { | |
43 | my ($theme) = m,themes/(.*)\.css,; | |
44 | my $css = read_file $_; | |
45 | $css .= $common_css; | |
46 | write_file "static/css/$theme.css", CSS::Minifier::XS::minify $css; | |
47 | } | |
8798626b MG |
48 | } |
49 | ||
cf2b0139 MG |
50 | sub make_js { |
51 | if (-f 'compiler.jar') { | |
52 | system java => -jar => 'compiler.jar', qw,-O SIMPLE --create_source_map static/js.map --js_output_file static/js.js --language_in ECMASCRIPT5_STRICT --source_map_location_mapping js/|/static/js/,, <js/*>; | |
53 | my $js = read_file 'static/js.js'; | |
54 | write_file 'static/js.js', '//# sourceMappingURL=/static/js.map', "\n", $js; | |
55 | system 'cp', '-rp', 'js', 'static/'; | |
56 | } else { | |
57 | my $js; | |
58 | $js .= read_file $_ for <js/*.js>; | |
59 | write_file 'static/js.js', JavaScript::Minifier::XS::minify $js; | |
60 | } | |
61 | } | |
62 | ||
63 | my $css_mtime = -M 'static/css/slate.css' // 0; | |
64 | for (<css/*>, <css/themes/*>) { | |
65 | if (!$css_mtime || $css_mtime > -M) { | |
66 | make_css; | |
67 | last | |
68 | } | |
69 | } | |
70 | ||
71 | my $js_mtime = -M 'static/js.js' // 0; | |
72 | for (<js/*>) { | |
73 | if (!$js_mtime || $js_mtime > -M) { | |
74 | make_js; | |
75 | last | |
76 | } | |
9cad7bdd | 77 | } |
69d77267 MG |
78 | |
79 | my $sprite_mtime = -M 'static/logos.png' // 0; | |
3d9a4393 | 80 | for (<logos/*>) { |
69d77267 MG |
81 | if (!$sprite_mtime || $sprite_mtime > -M) { |
82 | make_sprite; | |
83 | last | |
84 | } | |
9cad7bdd | 85 | } |
6eb2623e MG |
86 | |
87 | package | |
88 | Local::CSS::SpriteMaker; | |
89 | ||
90 | use parent qw/CSS::SpriteMaker/; | |
91 | ||
92 | sub _get_stylesheet_string { | |
93 | my $self = shift; | |
94 | my @ret = split "\n", $self->SUPER::_get_stylesheet_string(@_); | |
95 | shift @ret; | |
96 | @ret = sort @ret; | |
97 | unshift @ret, <<EOF; | |
98 | a.logo { | |
99 | background-image: url("https://static.mindcoding.ro/static/logos.png"); | |
100 | background-repeat: no-repeat; | |
101 | display: inline-block; | |
102 | vertical-align: middle; | |
103 | } | |
104 | EOF | |
105 | join "\n", @ret; | |
106 | } |