X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/0f1264a15b66ff3682c5ebe2b9af8d2936a302f9..41af4e92ea22b885a6651537e8780d7be6d27287:/common.inc.plp?ds=sidebyside diff --git a/common.inc.plp b/common.inc.plp index 8a13059..4bc68a6 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.17", $_ - ) } @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'); @@ -157,7 +155,8 @@ sub Html { my ($file) = $ENV{SCRIPT_FILENAME} =~ m{ ([^/]+) \.plp$ }x; - if (my $url = $meta->{canonical} // "/$file/$Request") { + $meta->{canonical} //= "/$file" . ($Request ne '' && "/$Request"); + if (my $url = $meta->{canonical}) { $url = "https://sheet.shiar.nl$url"; push @{ $meta->{raw} }, qq(); } @@ -165,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 '', $_ @@ -179,6 +180,19 @@ 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 sprintf '', $file;