X-Git-Url: http://git.shiar.net/sheet.git/blobdiff_plain/7dcd95ca1bc9fb7330103791695eec05085d67af..3afdb629211b357a3760e14b92e9966b2d414a0d:/common.inc.plp?ds=inline diff --git a/common.inc.plp b/common.inc.plp index a634733..6d6a532 100644 --- a/common.inc.plp +++ b/common.inc.plp @@ -72,12 +72,10 @@ sub stylesheet { } or warn "Unable to create style cookie: $@"; } - $style ||= exists $cookie{style} && $styles{ $cookie{style} } || $avail[0]; - - return map { sprintf( - '', - $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "/$_.css?1.18", $_ - ) } @avail; + $style ||= $styles{$_} for $cookie{style} || (); + my $setstyle = $style; + $style ||= $avail[0]; + return $setstyle; } sub checkmodified { @@ -141,11 +139,11 @@ sub Html { $header{content_type} = "text/html; charset=$meta->{charset}" unless $PLP::sentheaders; exit if $ENV{REQUEST_METHOD} eq 'HEAD'; - unshift @{ $meta->{raw} }, stylesheet($meta->{stylesheet}); - push @{ $meta->{raw} }, ( - '', + unshift @{ $meta->{raw} }, ( + '', ); + $meta->{stylesheet} = stylesheet($meta->{stylesheet}); if (my $img = $meta->{image}) { my $proto = sprintf('http%s://', !!$ENV{HTTPS} && 's'); @@ -166,7 +164,9 @@ sub Html { PLP_START { # leading output say ''; - say qq(); + my $rootattr = ''; + $rootattr .= qq( class="s-$_") for $meta->{stylesheet} || (); + say qq(); say ''; say ''; say sprintf '', $_ @@ -180,6 +180,10 @@ sub Html { say ''; say for map { @{$_} } $meta->{raw} || (); say '' if $Dev; + say "" for join($/, + "if (m = window.matchMedia('(monochrome)'))", + "(m.onchange = e => document.documentElement.classList.toggle('s-mono', e.matches))(m);", + ); say ''; say ''; say sprintf '', $file;