$header{content_type} = 'text/html; charset=utf-8';
sub stylesheet {
- my ($avail) = @_;
- my @avail = ref $avail eq 'ARRAY' ? @{$avail} : $avail or return;
+ my @avail = qw( light dark circus mono red );
my %styles = map {$_ => $_} @avail;
if (defined( my $setstyle = $get{style} )) {
} or warn "Unable to create style cookie: $@";
}
- $style ||= $styles{$_} for $cookie{style} || ();
my $setstyle = $style;
+ $style ||= $styles{$_} for $cookie{style} || ();
$style ||= $avail[0];
return $setstyle;
}
sub Data {
my ($filename) = @_;
my @data = eval {
- open my $cache, '<:raw', "data/$filename.json"
+ !exists $get{f} and open my $cache, '<:raw', "data/$filename.json"
or return do "./$filename.inc.pl"; # silent fallback to original code
require JSON;
local $/; # slurp
}
# default fallbacks
- $meta->{stylesheet} ||= [qw( light dark circus mono red )];
$meta->{charset} ||= 'utf-8';
$meta->{lang} ||= 'en';
unshift @{ $meta->{raw} }, (
'<link rel="stylesheet" type="text/css" media="all" href="/light.css?1.20">',
);
- $meta->{stylesheet} = stylesheet($meta->{stylesheet});
+ $meta->{stylesheet} = stylesheet();
if (my $img = $meta->{image}) {
my $proto = sprintf('http%s://', !!$ENV{HTTPS} && 's');
say '<link rel="icon" type="image/png" href="/clip.png">';
say for map { @{$_} } $meta->{raw} || ();
say '<meta name="robots" content="noindex">' if $Dev;
- say "<script>$_</script>" for join($/,
- "docroot = document.documentElement;",
- "if (docroot.className == '') {",
- "new Map([",
- "['s-mono','(monochrome)'],",
- "['s-dark','(prefers-color-scheme: dark)'],",
- "['s-circus','(prefers-contrast: more)'],",
- "]).forEach((q,c) => {",
- "if (m = window.matchMedia(q))",
- "(m.onchange = e => docroot.classList.toggle(c, e.matches))(m)",
- "})",
- "}",
- );
+ say '<script src="/prefer.js"></script>';
say '</head>';
say '';
say sprintf '<body id="%s">', $file;