common: mark dev pages as noindex to robots
[sheet.git] / common.inc.plp
index fe2a2878a6a09d8c5e7861b2bb6e7d12452e89d7..33fad39b084798f3abe666c901372b6ae19ed5e6 100644 (file)
@@ -1,6 +1,6 @@
 <:
+use 5.014;
 use utf8;
-use strict;
 use warnings;
 no  warnings 'qw';  # you know what you doing
 no  warnings 'uninitialized';  # save some useless checks for more legible code
@@ -12,8 +12,14 @@ use HTTP::Date;
 $PLP::ERROR = sub {
        my ($text, $html) = @_;
        print '<p class="error"><strong>Fatal error</strong>: '.$html."</p>\n\n";
+       warn $text;
 };
 
+BEGIN {
+       require Time::HiRes;
+       our $Time = [Time::HiRes::gettimeofday];
+}
+
 our $style;
 our $showkeys = !exists $get{keys} ? undef :
        ($get{keys} ne '0' && ($get{keys} || 'always'));
@@ -41,7 +47,7 @@ sub stylesheet {
 
        return join "\n", map { sprintf(
                '<link rel="%s" type="text/css" media="all" href="%s" title="%s">',
-               $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "/$_.css?1.8", $_
+               $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "/$_.css?1.9", $_
        ) } @_;
 }
 
@@ -96,6 +102,7 @@ sub Html {
        ref $_ eq 'ARRAY' and $_ = stylesheet(@$_)."\n" for $meta->{stylesheet};
 
        # other vars
+       my $Dev = $ENV{HTTP_HOST} =~ /\bdev\./;
        my ($file) = $ENV{SCRIPT_FILENAME} =~ m{ ([^/]+) \.plp$ }x;
 
        # leading output
@@ -112,11 +119,12 @@ sub Html {
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <link rel="icon" type="image/png" href="/clip.png">
 EOT
-       print $_, "\n" for $meta->{stylesheet} || ();
-       print $_, "\n" for $meta->{raw} || ();
-       print qq{</head>\n\n<body id="$file">\n};
+       say for $meta->{stylesheet} || ();
+       say for $meta->{raw} || ();
+       say '<meta name="robots" content="noindex">' if $Dev;
+       say qq{</head>\n\n<body id="$file">};
 
-       # dev indicator
+       # development version indicator
        printf '<p style="%s">beta</p>', join('; ',
                'position: fixed',
                'right: 1em',
@@ -125,7 +133,7 @@ EOT
                'border-width: 1ex 0',
                'z-index: 1',
                'background: inherit',
-       ) if $ENV{HTTP_HOST} =~ /\bdev\./;
+       ) if $Dev;
 
        # prepare trailing output
        PLP_END {
@@ -138,10 +146,11 @@ EOT
        created by <a href="http://shiar.nl/" rel="author">Shiar</a> •
        <a href="http://www.fsf.org/licensing/licenses/agpl-3.0.html" rel="license copyright"
         title="Licensed under the GNU Affero General Public License, version 3">AGPLv3</a>
-</p>
-
-</html>
 EOT
+               say sprintf '• %.3fs', Time::HiRes::tv_interval($Time) if $Dev;
+               say '</p>';
+               say '';
+               say '</html>';
        };
 }