X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/41af4e92ea22b885a6651537e8780d7be6d27287..dbf4a34af50113bb56c5dfaae3afeb6441e0cd8d:/common.inc.plp diff --git a/common.inc.plp b/common.inc.plp index 4bc68a6..1640884 100644 --- a/common.inc.plp +++ b/common.inc.plp @@ -54,8 +54,7 @@ our $style; $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} )) { @@ -72,8 +71,8 @@ sub stylesheet { } 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; } @@ -98,7 +97,7 @@ sub checkmodified { 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 @@ -127,7 +126,6 @@ sub Html { } # default fallbacks - $meta->{stylesheet} ||= [qw( light dark circus mono red )]; $meta->{charset} ||= 'utf-8'; $meta->{lang} ||= 'en'; @@ -143,7 +141,7 @@ sub Html { unshift @{ $meta->{raw} }, ( '', ); - $meta->{stylesheet} = stylesheet($meta->{stylesheet}); + $meta->{stylesheet} = stylesheet(); if (my $img = $meta->{image}) { my $proto = sprintf('http%s://', !!$ENV{HTTPS} && 's'); @@ -180,19 +178,7 @@ sub Html { say ''; say for map { @{$_} } $meta->{raw} || (); say '' if $Dev; - say "" 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 ''; say ''; say ''; say sprintf '', $file;