aboutsummaryrefslogtreecommitdiffstats
path: root/app/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/blog_posts_helper.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/app/helpers/blog_posts_helper.rb b/app/helpers/blog_posts_helper.rb
new file mode 100644
index 0000000..fb90e94
--- /dev/null
+++ b/app/helpers/blog_posts_helper.rb
@@ -0,0 +1,22 @@
+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
+end