Просмотр исходного кода

Update the routes and templates for the routing of tCMS by tPSGI

Two routes called redirect_permanent from Trog::Routes::HTML, which no
longer has it.  It is now a method of the tPSGI object in
$query->{tpsgi}, so the old about page and the old stylesheet URL would
have died.  The route for a talk was a regex with a capture, and tPSGI
routes by OpenAPI path templates, so it is now /talks/{fragment+}, and
it reads the fragment from $query->{input}.  The regex also required a
leading digit, so the route still answers 404 without one.  An exact
path, such as /talks/index.html, wins over the template.  The fragment
is percent-encoded before it goes in the Location header, so a request
cannot add a header.

routes.pm called Text::Xslate without loading it, so it now uses it.
The sponsors and FAQ pages set their own title, rather than show the
default title of the site.

The title bar linked the Perl Mongers logo from pm.org, where it no
longer exists, so every page had a broken image.  The theme now has its
own copy of the logo from its current place on that site.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
troglodyne-bot 21 часов назад
Родитель
Сommit
f28e2e9854
3 измененных файлов с 12 добавлено и 8 удалено
  1. BIN
      img/sys/pm-title.png
  2. 11 7
      routes.pm
  3. 1 1
      templates/html/components/title.tx

BIN
img/sys/pm-title.png


+ 11 - 7
routes.pm

@@ -7,6 +7,8 @@ no warnings 'experimental';
 use feature qw{signatures};
 
 use File::Basename qw{basename};
+use Text::Xslate;
+use URI::Escape qw{uri_escape_utf8};
 
 use lib 'lib';
 use Trog::Routes::HTML;
@@ -24,7 +26,7 @@ our $fb_app_id       = 'bogus';
 our %routes = (
     '/about.html' => {
         method   => 'GET',
-        callback => sub {Trog::Routes::HTML::redirect_permanent('/about') },
+        callback => sub ($query) { $query->{tpsgi}->redirect_permanent('/about') },
     },
     '/meetings.html' => {
         method   => 'GET',
@@ -61,15 +63,15 @@ our %routes = (
     },
     '/styles/houston.css' => {
         method   => 'GET',
-        callback => sub {Trog::Routes::HTML::redirect_permanent('/themes/houston.pm/styles/houston.css') },
+        callback => sub ($query) { $query->{tpsgi}->redirect_permanent('/themes/houston.pm/styles/houston.css') },
     },
-    '/talks/(\d.*)' => {
+    '/talks/{fragment+}' => {
         method   => 'GET',
-        callback => sub {
-            my ($query) = @_;
-            Trog::Routes::HTML::redirect_permanent("/assets/talks/$query->{fragment}")
+        callback => sub ($query) {
+            my $fragment = $query->{input}{fragment};
+            return $query->{tpsgi}->notfound($query) unless $fragment =~ m/\A\d/;
+            return $query->{tpsgi}->redirect_permanent( '/assets/talks/' . uri_escape_utf8( $fragment, q{^A-Za-z0-9\-._~/} ) );
         },
-        captures => ['fragment'],
     },
 );
 
@@ -78,11 +80,13 @@ my $processor = Text::Xslate->new(
 );
 
 sub sponsors ($args) {
+    $args->{title} = 'Sponsors';
     my $out = $processor->render('sponsors.tx');
     return Trog::Routes::HTML::index($args, $out);
 }
 
 sub faq ($args) {
+    $args->{title} = 'FAQ';
     my $out = $processor->render('faq.tx');
     return Trog::Routes::HTML::index($args, $out);
 }

+ 1 - 1
templates/html/components/title.tx

@@ -1,3 +1,3 @@
 <a href="http://www.pm.org/index.html">
-    <img alt="Perl Mongers' Site" src="https://www.pm.org/graphics/title.png" height="65" width="150" style="margin-top:.5rem; margin-right: .5rem;" />
+    <img alt="Perl Mongers' Site" src="<: $theme_dir :>/img/sys/pm-title.png" height="65" width="150" style="margin-top:.5rem; margin-right: .5rem;" />
 </a>