OSDN Git Service

Plugin: add "AddThumbnail" plugin
authorhylom <hylom@users.sourceforge.jp>
Fri, 19 Apr 2019 11:06:18 +0000 (20:06 +0900)
committerhylom <hylom@users.sourceforge.jp>
Fri, 19 Apr 2019 11:06:18 +0000 (20:06 +0900)
src/newslash_web/lib/Newslash/Plugin/AddThumbnail.pm [new file with mode: 0644]
src/newslash_web/lib/Newslash/Plugin/NewslashHelpers.pm
src/newslash_web/lib/Newslash/Web.pm

diff --git a/src/newslash_web/lib/Newslash/Plugin/AddThumbnail.pm b/src/newslash_web/lib/Newslash/Plugin/AddThumbnail.pm
new file mode 100644 (file)
index 0000000..e570d5b
--- /dev/null
@@ -0,0 +1,30 @@
+package Newslash::Plugin::AddThumbnail;
+use Mojo::Base 'Mojolicious::Plugin';
+use Data::Dumper;
+sub register {
+    my ($self, $app, $conf) = @_;
+
+    $app->hook(before_render => sub {
+                   my ($c, $args) = @_;
+                   return if $c->stash("thumbnail");
+                   my $cfg = $app->config->{Site} || {};
+                   my $base_url = $cfg->{base_url};
+                   my $icon_url = $base_url . $cfg->{topic_icon_base_url} . "/";
+
+                   my $item = $c->stash("item") || $args->{item};
+                   if ($item) {
+                       if (($item->{primary_topic} || {})->{image}) {
+                           $c->stash(thumbnail => $icon_url . $item->{primary_topic}->{image});
+                           return;
+                       }
+                   }
+                   if ($cfg->{default_thumbnail}) {
+                       $c->stash(thumbnail => $base_url . $cfg->{default_thumbnail});
+                       return;
+                   }
+               });
+}
+
+
+
+1;
index d01df43..ceeea8a 100644 (file)
@@ -244,7 +244,9 @@ sub _extract_description {
 }
 
 ######################################################################
-# 
+
+# insert_code / daclare: insert some codes programatically
+# this feature used to insert Captcha.
 
 use constant MARKERS => qw(begin_footer);
 my $marker_contents = {};
index 7bcfaac..98fd615 100644 (file)
@@ -236,6 +236,9 @@ sub startup {
     # Set Description automatically
     $app->plugin('Newslash::Plugin::AddDescription');
 
+    # Set Thumbnail automatically
+    $app->plugin('Newslash::Plugin::AddThumbnail');
+
     ############################################################
     #
     # Routing Settings