From 8f4f5364aaa15832b8d909ebf8e7009a114add4c Mon Sep 17 00:00:00 2001 From: hylom Date: Wed, 19 Jul 2017 20:02:47 +0900 Subject: [PATCH] add archive link to journals index --- .../lib/Newslash/Web/Controller/Index.pm | 32 ++++++++++++++++++---- .../templates/common/article/article.html.tt2 | 2 +- src/newslash_web/templates/index/journals.html.tt2 | 13 +++++++++ src/newslash_web/templates/index/root.html.tt2 | 5 ++-- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/src/newslash_web/lib/Newslash/Web/Controller/Index.pm b/src/newslash_web/lib/Newslash/Web/Controller/Index.pm index 8027af4e..870bee2a 100644 --- a/src/newslash_web/lib/Newslash/Web/Controller/Index.pm +++ b/src/newslash_web/lib/Newslash/Web/Controller/Index.pm @@ -36,8 +36,20 @@ sub root { sub journals { my $c = shift; - my $journals = $c->model('journals')->select(limit => 10, order_by => {date => 'DESC'}); - $c->render(journals => $journals); + my $items_per_page = $c->config->{IndexPage}->{story_per_page} || 10; + my $items = $c->model('journals')->select(limit => $items_per_page + 1, order_by => {date => 'DESC'}); + if (!$items) { + $c->rendered(404); + return; + } + + # check if next page exists + my $prev_page = {}; + if (@$items > $items_per_page) { + my $next_item = pop @$items; + $prev_page = _get_paging_item($next_item); + } + $c->render(journals => $items, prev_page => $prev_page); } # deprecated: moved to Comment.pm @@ -65,10 +77,10 @@ sub banned { } sub _get_paging_item { - my $story = shift; - return if !$story; + my $item = shift; + return if !$item; - my $dt = Newslash::Util::Formatters::parse_mysql_datetime($story->{time}); + my $dt = Newslash::Util::Formatters::parse_mysql_datetime($item->{time}); return if !$dt; $dt->set_time_zone('UTC'); @@ -79,9 +91,17 @@ sub _get_paging_item { $mm = "0$mm" if $mm < 10; $dd = "0$dd" if $dd < 10; + my $id; + if ($item->{content_type} eq "story") { + $id = $item->{stoid}; + } + elsif ($item->{content_type} eq "journal") { + $id = $item->{id}; + } + return { date =>"$yy/$mm/$dd", - sid => $story->{sid} + id => $id, }; } 1; diff --git a/src/newslash_web/templates/common/article/article.html.tt2 b/src/newslash_web/templates/common/article/article.html.tt2 index 2a77236c..808cf03d 100644 --- a/src/newslash_web/templates/common/article/article.html.tt2 +++ b/src/newslash_web/templates/common/article/article.html.tt2 @@ -6,7 +6,7 @@ IF story.content_type == 'poll'; content_id = story.qid; END; IF story.content_type == 'vote'; content_id = story.qid; END; -%] -
+

[%- IF story.primary_topic.image.length || x_template -%] diff --git a/src/newslash_web/templates/index/journals.html.tt2 b/src/newslash_web/templates/index/journals.html.tt2 index ed395e01..25643169 100644 --- a/src/newslash_web/templates/index/journals.html.tt2 +++ b/src/newslash_web/templates/index/journals.html.tt2 @@ -6,6 +6,19 @@ [%- INCLUDE common/article/article hide_bodytext=1%] [%- END -%] + +
+ [%- IF prev_page -%] + + ≪前の記事 + + [%- END -%] + [%- IF next_page -%] + + 次の記事≫ + + [%- END -%] +
[%- INCLUDE common/sidebar -%] diff --git a/src/newslash_web/templates/index/root.html.tt2 b/src/newslash_web/templates/index/root.html.tt2 index 2af81511..b70b15e5 100644 --- a/src/newslash_web/templates/index/root.html.tt2 +++ b/src/newslash_web/templates/index/root.html.tt2 @@ -6,15 +6,16 @@ [%- INCLUDE common/article/article %] [%- END -%] + -- 2.11.0