common: join stylesheets html inline
authorMischa POSLAWSKY <perl@shiar.org>
Wed, 29 Mar 2017 15:34:08 +0000 (17:34 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 10 Apr 2017 13:28:46 +0000 (15:28 +0200)
common.inc.plp

index 33fad39b084798f3abe666c901372b6ae19ed5e6..6330329cc907f5c27f400326037a39c255d521eb 100644 (file)
@@ -27,7 +27,9 @@ our $showkeys = !exists $get{keys} ? undef :
 $header{content_type} = 'text/html; charset=utf-8';
 
 sub stylesheet {
-       my %styles = map {$_ => $_} @_;
+       my ($avail) = @_;
+       my @avail = ref $avail eq 'ARRAY' ? @{$avail} : $avail or return;
+       my %styles = map {$_ => $_} @avail;
 
        if (defined( my $setstyle = $get{style} )) {
                $style = $styles{ $setstyle };
@@ -43,12 +45,12 @@ sub stylesheet {
                } or warn "Unable to create style cookie: $@";
        }
 
-       $style ||= exists $cookie{style} && $styles{ $cookie{style} } || $_[0];
+       $style ||= exists $cookie{style} && $styles{ $cookie{style} } || $avail[0];
 
-       return join "\n", map { sprintf(
+       return map { sprintf(
                '<link rel="%s" type="text/css" media="all" href="%s" title="%s">',
                $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "/$_.css?1.9", $_
-       ) } @_;
+       ) } @avail;
 }
 
 sub checkmodified {
@@ -99,7 +101,6 @@ sub Html {
        ref $_ eq 'ARRAY' and $_ = join ' ',  @$_ for $meta->{description};
        ref $_ eq 'ARRAY' and $_ = join ', ', @$_ for $meta->{keywords};
        ref $_ eq 'ARRAY' and $_ = join "\n", @$_ for $meta->{raw};
-       ref $_ eq 'ARRAY' and $_ = stylesheet(@$_)."\n" for $meta->{stylesheet};
 
        # other vars
        my $Dev = $ENV{HTTP_HOST} =~ /\bdev\./;
@@ -119,7 +120,7 @@ sub Html {
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <link rel="icon" type="image/png" href="/clip.png">
 EOT
-       say for $meta->{stylesheet} || ();
+       say for stylesheet($meta->{stylesheet});
        say for $meta->{raw} || ();
        say '<meta name="robots" content="noindex">' if $Dev;
        say qq{</head>\n\n<body id="$file">};