Split archive in past and future list

This commit is contained in:
Stefan Schlott 2013-08-29 10:20:25 +02:00
parent b68b3c9a62
commit ff16ff78a0
3 changed files with 6 additions and 4 deletions

View file

@ -1,7 +1,8 @@
require 'ostruct'
def generate_yearly_archive(articles, date_attribute, basepath, title, templatename = 'article_archive', attributes = {})
currentyear = Time.now.year
today = Time.now
currentyear = today.year
yearmap = articles.group_by { |item| item[date_attribute].year }
if !yearmap.has_key?(currentyear)
yearmap[currentyear] = []
@ -10,6 +11,7 @@ def generate_yearly_archive(articles, date_attribute, basepath, title, templaten
yearlist.each_index { |i|
year = yearlist[i]
yearmap[year].sort! { |a,b| b[date_attribute] <=> a[date_attribute] }
pastfuture = yearmap[year].partition { |a| a[date_attribute].to_datetime > today.to_datetime }
linkprev = if (i>0)
", :linkprev => OpenStruct.new(:title => '#{yearlist[i-1]}', :link => '#{basepath}/#{yearlist[i-1]}/')"
else
@ -22,7 +24,7 @@ def generate_yearly_archive(articles, date_attribute, basepath, title, templaten
end
@items << Nanoc::Item.new(
"<%= render '#{templatename}' #{linkprev} #{linknext} %>",
attributes.merge({ :title => "#{title} #{year}", :kind => "page", :archiveitems => yearmap[year] }),
attributes.merge({ :title => "#{title} #{year}", :kind => "page", :futureitems => pastfuture[0], :pastitems => pastfuture[1] }),
"#{basepath}/#{year}/")
}
end