diff options
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/blog_posts_helper.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/app/helpers/blog_posts_helper.rb b/app/helpers/blog_posts_helper.rb index 965eb8f..6b4066a 100644 --- a/app/helpers/blog_posts_helper.rb +++ b/app/helpers/blog_posts_helper.rb @@ -6,11 +6,17 @@ module BlogPostsHelper html << t('blog.shared.archives') html << '</h2><nav><ul>' links = [] + super_old_links = [] posts.each do |e| - links << e.published_at.strftime('%m/%Y') + if e.published_at >= Time.now.end_of_year.advance(:years => -3) + links << e.published_at.strftime('%m/%Y') + else + super_old_links << e.published_at.strftime('01/%Y') + end end links.uniq! + super_old_links.uniq! links.each do |l| year = l.split('/')[1] month = l.split('/')[0] @@ -20,6 +26,14 @@ module BlogPostsHelper html << link_to(text, archive_blog_posts_path(:year => year, :month => month)) html << "</li>" end + super_old_links.each do |l| + year = l.split('/')[1] + count = BlogPost.by_year(Time.parse(l)).size + text = "#{year} (#{count})" + html << "<li>" + html << link_to(text, archive_blog_posts_path(:year => year)) + html << "</li>" + end html << '</ul></nav></section>' html.html_safe end |