X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FPlack%2FApp%2FGruntmaster.pm;h=5530c73dab29dd2eab00d60d715f73e2dfbf3b40;hb=f34254b8ee796c7b3416d6b6b31886c10fcf62c1;hp=60ab49f963b184207cdbf6e507c6e5b1b13bff52;hpb=5a2112d32984d8621a6fb8a461b85ddf9c37e9ba;p=plack-app-gruntmaster.git diff --git a/lib/Plack/App/Gruntmaster.pm b/lib/Plack/App/Gruntmaster.pm index 60ab49f..5530c73 100644 --- a/lib/Plack/App/Gruntmaster.pm +++ b/lib/Plack/App/Gruntmaster.pm @@ -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$/ } ; + 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']] }