]> iEval git - gruntmaster-page.git/blob - make_static.PL
Remove Google Analytics
[gruntmaster-page.git] / make_static.PL
1 #!/usr/bin/perl
2 use v5.14;
3 use warnings;
4
5 use CSS::Minifier::XS qw//;
6 use CSS::SpriteMaker;
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
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 );
22
23 $maker->make_sprite(
24 source_images => ['logos/'],
25 target_file => 'static/logos.png',
26 add_extra_padding => 10,
27 );
28
29 $maker->print_css(
30 filename => 'css/logos.css',
31 sprite_filename => 'https://static.mindcoding.ro/static/logos.png',
32 );
33
34 system 'optipng', '-o7', '-zm1-9', 'static/logos.png';
35 }
36
37 sub 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 }
46 }
47
48 sub 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
61 my $css_mtime = -M 'static/css/slate.css' // 0;
62 for (<css/*>, <css/themes/*>) {
63 if (!$css_mtime || $css_mtime > -M) {
64 make_css;
65 last
66 }
67 }
68
69 my $js_mtime = -M 'static/js.js' // 0;
70 for (<js/*>) {
71 if (!$js_mtime || $js_mtime > -M) {
72 make_js;
73 last
74 }
75 }
76
77 my $sprite_mtime = -M 'static/logos.png' // 0;
78 for (<logos/*>) {
79 if (!$sprite_mtime || $sprite_mtime > -M) {
80 make_sprite;
81 last
82 }
83 }
84
85 package
86 Local::CSS::SpriteMaker;
87
88 use parent qw/CSS::SpriteMaker/;
89
90 sub _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;
96 a.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 }
102 EOF
103 join "\n", @ret;
104 }
This page took 0.056367 seconds and 4 git commands to generate.