our @EXPORT = qw/render render_article/;
use File::Slurp qw/read_file/;
- use HTML::Seamstress;
+ use HTML::Element::Library;
+ use HTML::TreeBuilder;
use POSIX qw//;
use Data::Dumper qw/Dumper/;
my %page_cache;
for (<tmpl/*>) {
my ($tmpl, $lang) = m,tmpl/(\w+)\.(\w+),;
- my $builder = HTML::Seamstress->new;
+ my $builder = HTML::TreeBuilder->new;
$builder->ignore_unknown(0);
$page_cache{$tmpl, $lang} = $builder->parse_file($_);
}
$process->($tree, %args) if $process;
$_->detach for $tree->look_down(static => $args{static} ? 'no' : 'yes');
$_->attr('static', undef) for $tree->look_down(sub {$_[0]->attr('static')});
- $_->attr('smap', undef) for $tree->look_down(sub {$_[0]->attr('defmap')});
+ $_->attr('smap', undef) for $tree->look_down(sub {$_[0]->attr('smap')});
$tree->as_HTML;
}
+my $logo = read_file 'mclogo.svg';
+$logo =~ y/\n//d;
+$logo =~ s/(\s+)/ /g;
+
sub process_skel {
my ($tree, %args) = @_;
+ $tree->fid('logo')->replace_with(literal $logo);
$tree->content_handler(
title => $args{title},
content => literal $args{meat});
if ($args{contest_stop}) {
$tree->fid('solution')->detach;
$tree->fid('solution_modal')->detach;
- my $score = $tree->fid('score');
- $score->attr('data-start' => $args{open_time});
- $score->attr('data-stop' => $args{contest_stop});
- $score->attr('data-value' => $args{value});
+ $tree->fid('score')->replace_content($args{value});
$tree->fid('countdown')->attr('data-stop' => $args{contest_stop});
} else {
$tree->fid('job_log')->edit_href(sub{$_ .= "&private=$args{private}"}) if $args{private};
use warnings;
use CSS::Minifier::XS qw//;
+use CSS::SpriteMaker;
use JavaScript::Minifier::XS qw//;
+ use IO::Compress::Gzip qw/gzip/;
use File::Slurp qw/read_file write_file/;
mkdir 'static';
mkdir 'static/css';
+sub make_sprite {
+ my $maker = Local::CSS::SpriteMaker->new(
+ css_class_prefix => 'logo-',
+ rc_override_classname => sub {
+ my ($name) = @_;
+ $name =~ s/-light/.logo-light/r;
+ }
+ );
+
+ $maker->make_sprite(
+ source_images => ['logos/'],
+ target_file => 'static/logos.png',
+ add_extra_padding => 10,
+ );
+
+ $maker->print_css(
+ filename => 'css/logos.css',
+ sprite_filename => '/static/logos.png',
+ );
+
+ system 'pngnq-s9', '-s1', 'static/logos.png';
+ system 'optipng', '-o7', '-zm1-9', 'static/logos-nq8.png';
+ rename 'static/logos-nq8.png', 'static/logos.png';
+}
+
+ sub gzip_file {
+ my ($file) = @_;
+ gzip $file => "$file.gz", -Level => 9, Minimal => 1;
+ }
+
sub make_css {
my $common_css;
$common_css .= read_file $_ for <css/*.css>;
my $css = read_file $_;
$css .= $common_css;
write_file "static/css/$theme.css", CSS::Minifier::XS::minify $css;
+ gzip_file "static/css/$theme.css";
}
}
$js .= read_file $_ for <js/*.js>;
write_file 'static/js.js', JavaScript::Minifier::XS::minify $js;
}
+ gzip_file 'static/js.js';
}
my $css_mtime = -M 'static/css/slate.css' // 0;
last
}
}
+
+my $sprite_mtime = -M 'static/logos.png' // 0;
+for (<logos/*>) {
+ if (!$sprite_mtime || $sprite_mtime > -M) {
+ make_sprite;
+ last
+ }
+}
+
+package
+ Local::CSS::SpriteMaker;
+
+use parent qw/CSS::SpriteMaker/;
+
+sub _get_stylesheet_string {
+ my $self = shift;
+ my @ret = split "\n", $self->SUPER::_get_stylesheet_string(@_);
+ shift @ret;
+ @ret = sort @ret;
+ unshift @ret, <<EOF;
+a.logo {
+ background-image: url("/static/logos.png");
+ background-repeat: no-repeat;
+ display: inline-block;
+ vertical-align: middle;
+}
+EOF
+ join "\n", @ret;
+}