OSDN Git Service

add Plugin::Canonical
authorhylom <hylom@users.sourceforge.jp>
Mon, 2 Oct 2017 13:16:52 +0000 (22:16 +0900)
committerhylom <hylom@users.sourceforge.jp>
Mon, 2 Oct 2017 13:16:52 +0000 (22:16 +0900)
src/newslash_web/lib/Newslash/Plugin/Canonical.pm [new file with mode: 0644]
src/newslash_web/lib/Newslash/Web.pm

diff --git a/src/newslash_web/lib/Newslash/Plugin/Canonical.pm b/src/newslash_web/lib/Newslash/Plugin/Canonical.pm
new file mode 100644 (file)
index 0000000..2738c9d
--- /dev/null
@@ -0,0 +1,24 @@
+package Newslash::Plugin::Canonical;
+use Mojo::Base 'Mojolicious::Plugin';
+use Mojo::URL;
+
+use POSIX qw(strftime locale_h);
+
+sub register {
+    my ($self, $app, $conf) = @_;
+
+    $app->hook(before_render => sub {
+                   my ($c, $args) = @_;
+                   return if $c->stash('canonical');
+                   my $url = Mojo::URL->new($c->url_for);
+                   $url->host('srad.jp');
+                   $url->port('');
+                   $url->scheme('https');
+                   $c->stash(canonical => $url->to_string);
+               });
+    #$app->helper(canonical => sub { state $canonical = $self; });
+}
+
+
+
+1;
index e861b80..a7d0f06 100644 (file)
@@ -97,6 +97,9 @@ sub startup {
         $app->plugin('Newslash::Plugin::ReCaptcha');
     }
 
+    # set canocal (for test.srad.jp)
+    $app->plugin('Newslash::Plugin::Canonical');
+
     # Event Que
     $app->plugin('Newslash::Plugin::EventQue');