OSDN Git Service

/tag/: fix paging
[newslash/newslash.git] / src / newslash_web / lib / Newslash / Web / Controller / Tag.pm
index 593efed..b1bea8e 100644 (file)
@@ -28,16 +28,16 @@ sub list_tagged_items {
     my $type = $c->stash('type');
 
     # check parameter
-    my $page_num = $c->param('page') || 0;
+    my $page_num = $c->param('page') || 1;
     my $config = $c->app->config("Timeline") || {};
     my $limit = $config->{item_per_page} || 10;
-    my $offset = $limit * $page_num;
+    my $offset = $limit * ($page_num - 1);
 
     my $show_future = $user->{is_admin} ? 1 : 0;
     my $show_nonpublic = $user->{is_admin} ? 1 : 0;
 
-    if ($type && !any { $_ eq $type } qw(story journal submission)) {
-        $c->rendered(400);
+    if ($page_num < 1 || $type && !any { $_ eq $type } qw(story journal submission)) {
+        $c->rendered(404);
         return;
     }
 
@@ -89,6 +89,7 @@ sub list_tagged_items {
 
     my $page = { type => "tag",
                  tag_name => $topic_name,
+                 tag_keyword => $topics->[0]->{keyword},
                  content_type => $type,
                  number => $page_num,
                  has_prev => @$items > $limit,