aboutsummaryrefslogtreecommitdiffstats
path: root/app/helpers/blog_posts_helper.rb
blob: e690a51f90fbffa5d7dbe67fb27f428d5908ef4a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module BlogPostsHelper
  def blog_archive_list
    posts = BlogPost.select('published_at').all_previous
    return nil if posts.blank?
    html = '<section id="blog_archive_list"><h1>Archives</h1><nav>'
    links = []

    posts.each do |e|
      links << e.published_at.strftime('%m/%Y')
    end
    links.uniq!
    links.each do |l|
      year = l.split('/')[1]
      month = l.split('/')[0]
      count = BlogPost.by_archive(Time.parse(l)).size
      text = "#{Date::MONTHNAMES[month.to_i]} #{year} (#{count})"
      html += link_to(text, archive_blog_posts_path(:year => year, :month => month))
    end
    html += '</nav></section>'
    html.html_safe
  end

  def next_or_previous?(post)
    post.next.present? or post.prev.present?
  end
end