$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} )) {
}
# 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 for map { @{$_} } $meta->{raw} || ();
say '<meta name="robots" content="noindex">' if $Dev;
say "<script>$_</script>" for join($/,
- "if (m = window.matchMedia('(monochrome)'))",
- "(m.onchange = e => document.documentElement.classList.toggle('s-mono', e.matches))(m);",
+ "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 '</head>';
say '';