Commit f91e8afa authored by James Thompson's avatar James Thompson Committed by Uģis Ozols
Browse files

fix for archive issues

parent 5287eec8
.DS_Store
Gemfile.lock
spec/dummy
.idea
\ No newline at end of file
......@@ -28,23 +28,16 @@ module Refinery
end
end
def news_item_archive_link(item)
if item.publish_date >= Time.now.end_of_year.advance(:years => -3)
post_date = item.publish_date.strftime('%m/%Y')
year = post_date.split('/')[1]
month = post_date.split('/')[0]
count = News::Item.by_archive(Time.parse(post_date)).size
text = t("date.month_names")[month.to_i] + " #{year} (#{count})"
link_to(text, refinery.news_items_archive_path(:year => year, :month => month))
else
post_date = post.publish_date.strftime('01/%Y')
year = post_date.split('/')[1]
count = Refinery::News::Item.by_year(Time.parse(post_date)).size
text = "#{year} (#{count})"
link_to(text, refinery.news_items_archive_path(:year => year))
def news_item_archive_links
html = ''
@item_months = ::Refinery::News::Item.published.group_by {|i| i.publish_date.beginning_of_month}
@item_months.each do |month, items|
if items.present?
text = "#{t("date.month_names")[month.month]} #{month.year} (#{items.count})"
html += "<li>#{link_to(text, refinery.news_items_archive_path(:year => month.year, :month => month.month))}</li>"
end
end
content_tag('ul', raw(html))
end
end
end
......
<section id="news_archive_widget">
<h2><%= t('archives', :scope => 'refinery.news.shared') %></h2>
<nav>
<ul>
<% items.each do |item| %>
<li><%= news_item_archive_link(item) %></li>
<% end %>
</ul>
<%= news_item_archive_links %>
</nav>
</section>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment