OSDN Git Service

implement sub-section RSS
authorhylom <hylom@users.sourceforge.jp>
Mon, 7 Jan 2019 10:35:00 +0000 (19:35 +0900)
committerhylom <hylom@users.sourceforge.jp>
Mon, 7 Jan 2019 10:35:00 +0000 (19:35 +0900)
src/newslash_web/lib/Newslash/Plugin/Stories.pm
src/newslash_web/lib/Newslash/Web/Controller/Rss.pm
src/newslash_web/templates/rss/sradjp.xml.tt2

index a689187..00f9137 100644 (file)
@@ -28,11 +28,12 @@ sub related_stories {
 }
 
 sub latest {
-    my ($self, $limit) = @_;
+    my $self = shift;
+    my $args = {@_};
     my $c = $self->c;
 
     my $user = $c->stash('user');
-    $limit ||= $c->_get_config("item_per_page", 10);
+    my $limit = $args->{limit} || $c->_get_config("item_per_page", 10);
     my $show_future = $user->{is_admin} ? 1 : 0;
     my $show_nonpublic = $user->{is_admin} ? 1 : 0;
 
index a230df7..3a2b7b0 100644 (file)
@@ -1,6 +1,7 @@
 package Newslash::Web::Controller::Rss;
 use Mojo::Base 'Newslash::Web::Controller';
 use Mojo::Util qw(dumper);
+use List::Util qw(any);
 
 use DateTime;
 use DateTime::Format::MySQL;
@@ -8,7 +9,10 @@ use Newslash::Util::Formatters;
 use Newslash::Util::Items;
 
 use constant CACHE_SEC => 30;
-
+use constant SUB_SECTIONS => qw(
+                                   apple askslashdot developers hardware idle interview
+                                   it linux mobile opensource review science security slash yro
+                              );
 sub timeline {
     my $c = shift;
     my $type = $c->stash("rss_type") || "";
@@ -23,7 +27,18 @@ sub timeline {
                                   limit => $limit,
                                   order_by => {create_time => 'desc'},
                                  );
+    } elsif (any { $type eq $_} (SUB_SECTIONS)) {
+        # get tid
+        my $topic = $c->model("topics")->select(keyword => $type);
+        my $stories = $c->ezcache->model('stories', { expire => CACHE_SEC });
+        $items = $stories->select(hide_future => 1,
+                                  public_only => 1,
+                                  limit => $limit,
+                                  tid => $topic->{tid},
+                                  order_by => {create_time => 'desc'},
+                                 );
     } else {
+        # select by tag
         $c->rendered(404);
         return;
     }
index 3d93842..224e427 100644 (file)
@@ -1,4 +1,4 @@
-[%- items = helpers.stories.latest(20) -%]
+[%- items = helpers.stories.latest("limit", 20) -%]
 <?xml version="1.0" encoding="utf-8"?>
 
 <rdf:RDF