Skip to content

Instantly share code, notes, and snippets.

@nlindley
Forked from ilkka/archivegenerator.rb
Last active December 22, 2015 03:19
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nlindley/6409441 to your computer and use it in GitHub Desktop.
module Jekyll
class ArchiveGenerator < Generator
safe true
def generate(site)
collate_by_month(site.posts).each do |month, posts|
page = ArchivePage.new(site, month, posts)
site.pages << page
end
end
private
def collate_by_month(posts)
collated = {}
posts.each do |post|
key = "%04d/%02d" % [post.date.year, post.date.month]
if collated.has_key? key
collated[key] << post
else
collated[key] = [post]
end
end
collated
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment