]> iEval git - gruntmaster-page.git/blobdiff - lib/Plack/App/Gruntmaster.pm
Add article support
[gruntmaster-page.git] / lib / Plack / App / Gruntmaster.pm
index 60ab49f963b184207cdbf6e507c6e5b1b13bff52..5530c73dab29dd2eab00d60d715f73e2dfbf3b40 100644 (file)
@@ -7,6 +7,7 @@ use parent qw/Plack::Component/;
 no if $] >= 5.017011, warnings => 'experimental::smartmatch';
 our $VERSION = '5999.000_001';
 
+use File::Slurp qw/read_file/;
 use HTTP::Negotiate qw/choose/;
 use Plack::Request;
 
@@ -24,6 +25,20 @@ sub call {
                return $obj->generate($format, $env->{'psgix.logger'}, map { $_ // '' } @args);
        }
 
+       if ($r->method eq 'GET' || $r->method eq 'HEAD') {
+               my $article = $r->path eq '/' ? '/index' : $r->path;
+               $article = substr $article, 1;
+               $article =~ tr,/,_,;
+               my @variants = grep { !/\.title$/ } <a/$article.*>;
+               if (@variants) {
+                       my $lang = choose [ map { [$_, 1, 'text/html', undef, undef, $_, undef] } map { /\.(.+)$/ } @variants ], $r->headers;
+                       my $content = read_file "a/$article.$lang";
+                       my $title = read_file "a/$article.$lang.title";
+                       my $html = Gruntmaster::Page::Base::header($lang, $title) . $content . Gruntmaster::Page::Base::footer($lang);
+                       return [200, ['Content-Type' => 'text/html', 'Content-Language' => $lang, 'Vary' => 'Accept-Language'], [$html] ]
+               }
+       }
+
        [404, ['Content-Type' => 'text/plain'], ['Not found']]
 }
 
This page took 0.022521 seconds and 4 git commands to generate.