X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/5299da1556ec4ccf5c93fea0d1c4dcef5f6bb180..dbf4a34af50113bb56c5dfaae3afeb6441e0cd8d:/common.inc.plp diff --git a/common.inc.plp b/common.inc.plp index 0754d85..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,12 +71,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.14", $_ - ) } @avail; + my $setstyle = $style; + $style ||= $styles{$_} for $cookie{style} || (); + $style ||= $avail[0]; + return $setstyle; } sub checkmodified { @@ -100,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 @@ -129,7 +126,6 @@ sub Html { } # default fallbacks - $meta->{stylesheet} ||= [qw( light dark circus mono red )]; $meta->{charset} ||= 'utf-8'; $meta->{lang} ||= 'en'; @@ -141,11 +137,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(); if (my $img = $meta->{image}) { my $proto = sprintf('http%s://', !!$ENV{HTTPS} && 's'); @@ -157,7 +153,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 +162,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 +178,7 @@ sub Html { say ''; say for map { @{$_} } $meta->{raw} || (); say '' if $Dev; + say ''; say ''; say ''; say sprintf '', $file;