General functionality "yearly archive"
This commit is contained in:
parent
f67285f37c
commit
4c872a7be8
2 changed files with 23 additions and 18 deletions
|
|
@ -2,22 +2,5 @@ require 'ostruct'
|
||||||
|
|
||||||
def generate_archive_pages()
|
def generate_archive_pages()
|
||||||
articles = items.select { |i| i[:kind] == 'article' }
|
articles = items.select { |i| i[:kind] == 'article' }
|
||||||
yearmap = articles.group_by { |item| item[:created_at].year }
|
generate_yearly_archive(articles, '/archives/articles', 'Blogarchiv')
|
||||||
yearmap.keys.each { |year|
|
|
||||||
# Simplified assumption: At least one blog post each year
|
|
||||||
linkprev = if (year>yearmap.keys.min)
|
|
||||||
", :linkprev => OpenStruct.new(:title => #{year-1}, :link => '/archives/articles/#{year-1}/')"
|
|
||||||
else
|
|
||||||
""
|
|
||||||
end
|
|
||||||
linknext = if (year<yearmap.keys.max)
|
|
||||||
", :linknext => OpenStruct.new(:title => #{year+1}, :link => '/archives/articles/#{year+1}/')"
|
|
||||||
else
|
|
||||||
""
|
|
||||||
end
|
|
||||||
@items << Nanoc::Item.new(
|
|
||||||
"<%= render 'article_archive', :year => #{year} #{linkprev} #{linknext} %>",
|
|
||||||
{ :title => "Blogarchiv #{year}", :kind => "fullpage" },
|
|
||||||
"/archives/articles/#{year}/")
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
22
lib/yearlyarchive.rb
Normal file
22
lib/yearlyarchive.rb
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
require 'ostruct'
|
||||||
|
|
||||||
|
def generate_yearly_archive(articles, basepath, title, templatename = 'article_archive')
|
||||||
|
yearmap = articles.group_by { |item| item[:created_at].year }
|
||||||
|
yearmap.keys.each { |year|
|
||||||
|
# Simplified assumption: At least one blog post each year
|
||||||
|
linkprev = if (year>yearmap.keys.min)
|
||||||
|
", :linkprev => OpenStruct.new(:title => #{year-1}, :link => '#{basepath}/#{year-1}/')"
|
||||||
|
else
|
||||||
|
""
|
||||||
|
end
|
||||||
|
linknext = if (year<yearmap.keys.max)
|
||||||
|
", :linknext => OpenStruct.new(:title => #{year+1}, :link => '#{basepath}/#{year+1}/')"
|
||||||
|
else
|
||||||
|
""
|
||||||
|
end
|
||||||
|
@items << Nanoc::Item.new(
|
||||||
|
"<%= render '#{templatename}', :year => #{year} #{linkprev} #{linknext} %>",
|
||||||
|
{ :title => "#{title} #{year}", :kind => "fullpage" },
|
||||||
|
"#{basepath}/#{year}/")
|
||||||
|
}
|
||||||
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue