lib/helpers.rb
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
require 'redcloth' module Nanoc3::Helpers::Tagging def site_tags ts = {} @items.each do |p| next unless p[:tags] p[:tags].each do |t| if ts[t] ts[t] = ts[t]+1 else ts[t] = 1 end end end ts end def tag_link_with_count(tag, count) %{#{link_for_tag(tag, '/tags/')} (#{count})} end def sorted_site_tags site_tags.sort{|a, b| a[1] <=> b[1]}.reverse end end module Nanoc3::Helpers::Site def latest_articles(max=nil) total = @site.items.select{|p| p.attributes[:date] && p.attributes[:type] == 'article'}.sort{|a, b| a.attributes[:date] <=> b.attributes[:date]}.reverse max ||= total.length total[0..max-1] end def popular_articles(max=nil) total = @site.items.select{|p| p.attributes[:date] && p.attributes[:type] == 'article' && p.attributes[:popular]}.sort{|a, b| a.attributes[:date] <=> b.attributes[:date]}.reverse max ||= total.length total[0..max-1] end def articles_by_month articles = latest_articles m_articles = [] index = -1 current_month = "" articles.each do |a| next unless a.attributes[:date] month = a.attributes[:date].strftime("%B %Y") if current_month != month then # new month m_articles << [month, [a]] index = index + 1 current_month = month else # same month m_articles[index][1] << a end end m_articles end def month_link_with_count(month, count) permalink = month.downcase.gsub /\s/, '-' %{<a href="/archives/#{permalink}/">#{month}</a> (#{count})} end end include Nanoc3::Helpers::Tagging include Nanoc3::Helpers::Site include Nanoc3::Helpers::Rendering |