]> iEval git - gruntmaster-page.git/blame - make_static.PL
Remove Google Analytics
[gruntmaster-page.git] / make_static.PL
CommitLineData
8798626b
MG
1#!/usr/bin/perl
2use v5.14;
3use warnings;
4
5use CSS::Minifier::XS qw//;
6eb2623e 6use CSS::SpriteMaker;
8798626b
MG
7use JavaScript::Minifier::XS qw//;
8
9use File::Slurp qw/read_file write_file/;
10
11mkdir 'static';
12mkdir 'static/css';
13
69d77267
MG
14sub 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
69d77267
MG
34 system 'optipng', '-o7', '-zm1-9', 'static/logos.png';
35}
c9dee865 36
cf2b0139
MG
37sub make_css {
38 my $common_css;
39 $common_css .= read_file $_ for <css/*.css>;
40 for (<css/themes/*>) {
41 my ($theme) = m,themes/(.*)\.css,;
42 my $css = read_file $_;
43 $css .= $common_css;
44 write_file "static/css/$theme.css", CSS::Minifier::XS::minify $css;
45 }
8798626b
MG
46}
47
cf2b0139
MG
48sub make_js {
49 if (-f 'compiler.jar') {
50 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/*>;
51 my $js = read_file 'static/js.js';
52 write_file 'static/js.js', '//# sourceMappingURL=/static/js.map', "\n", $js;
53 system 'cp', '-rp', 'js', 'static/';
54 } else {
55 my $js;
56 $js .= read_file $_ for <js/*.js>;
57 write_file 'static/js.js', JavaScript::Minifier::XS::minify $js;
58 }
59}
60
61my $css_mtime = -M 'static/css/slate.css' // 0;
62for (<css/*>, <css/themes/*>) {
63 if (!$css_mtime || $css_mtime > -M) {
64 make_css;
65 last
66 }
67}
68
69my $js_mtime = -M 'static/js.js' // 0;
70for (<js/*>) {
71 if (!$js_mtime || $js_mtime > -M) {
72 make_js;
73 last
74 }
9cad7bdd 75}
69d77267
MG
76
77my $sprite_mtime = -M 'static/logos.png' // 0;
3d9a4393 78for (<logos/*>) {
69d77267
MG
79 if (!$sprite_mtime || $sprite_mtime > -M) {
80 make_sprite;
81 last
82 }
9cad7bdd 83}
6eb2623e
MG
84
85package
86 Local::CSS::SpriteMaker;
87
88use parent qw/CSS::SpriteMaker/;
89
90sub _get_stylesheet_string {
91 my $self = shift;
92 my @ret = split "\n", $self->SUPER::_get_stylesheet_string(@_);
93 shift @ret;
94 @ret = sort @ret;
95 unshift @ret, <<EOF;
96a.logo {
97 background-image: url("https://static.mindcoding.ro/static/logos.png");
98 background-repeat: no-repeat;
99 display: inline-block;
100 vertical-align: middle;
101}
102EOF
103 join "\n", @ret;
104}
This page took 0.034789 seconds and 4 git commands to generate.