I've added a new feature others might be interested in using.
I tend to be very hit-or-miss when I post to my blog. Unfortunately,
this means some months actually go by without a single post. Even
many months in a row.
Rather than see:
March 2008 (0)
Feburary 2008 (0)
January 2008 (0)
I wanted to just omit these. I found no real way to do this in
liquid, but I'm a liquid novice. Make that newbie.
So, rather than using
{% for month in articles.months %}
I can now use
{% for month in articles.months_with_articles %}
Add this to the end of app/drops/section_drop.rb, right before the
final 'end' line, and you can too:
def months_with_articles
if @months_with_articles.nil?
@months_with_articles = []
@source.articles.find(:all, :order => 'published_at desc', :select
=> 'published_at').each do |article|
if article.published_at
this_month = article.published_at.beginning_of_month
unless @months_with_articles.include?(this_month)
@months_with_articles << this_month
end
end
end
end
@months_with_articles
end