Enhance yearly archive: Skip years without data
This commit is contained in:
parent
4c872a7be8
commit
5dd85b2777
1 changed files with 7 additions and 6 deletions
|
|
@ -2,15 +2,16 @@ require 'ostruct'
|
||||||
|
|
||||||
def generate_yearly_archive(articles, basepath, title, templatename = 'article_archive')
|
def generate_yearly_archive(articles, basepath, title, templatename = 'article_archive')
|
||||||
yearmap = articles.group_by { |item| item[:created_at].year }
|
yearmap = articles.group_by { |item| item[:created_at].year }
|
||||||
yearmap.keys.each { |year|
|
yearlist = yearmap.keys.sort
|
||||||
# Simplified assumption: At least one blog post each year
|
yearlist.each_index { |i|
|
||||||
linkprev = if (year>yearmap.keys.min)
|
year = yearlist[i]
|
||||||
", :linkprev => OpenStruct.new(:title => #{year-1}, :link => '#{basepath}/#{year-1}/')"
|
linkprev = if (i>0)
|
||||||
|
", :linkprev => OpenStruct.new(:title => '#{yearlist[i-1]}', :link => '#{basepath}/#{yearlist[i-1]}/')"
|
||||||
else
|
else
|
||||||
""
|
""
|
||||||
end
|
end
|
||||||
linknext = if (year<yearmap.keys.max)
|
linknext = if (i<yearlist.size-1)
|
||||||
", :linknext => OpenStruct.new(:title => #{year+1}, :link => '#{basepath}/#{year+1}/')"
|
", :linknext => OpenStruct.new(:title => '#{yearlist[i+1]}', :link => '#{basepath}/#{yearlist[i+1]}/')"
|
||||||
else
|
else
|
||||||
""
|
""
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue