Skip to content

Instantly share code, notes, and snippets.

@bighairydave
Forked from nlindley/archivegenerator.rb
Last active August 29, 2015 14:22
Show Gist options
  • Save bighairydave/fabc06e1e3d6d36cee50 to your computer and use it in GitHub Desktop.
Save bighairydave/fabc06e1e3d6d36cee50 to your computer and use it in GitHub Desktop.
Collate Jekyll posts by month and year, and create both archive pages and a monthly XML feed
module Jekyll
class ArchiveGenerator < Generator
safe true
def generate(site)
feeddata = {}
collate_by_month(site.posts).each do |month, posts|
page = ArchivePage.new(site, month, posts)
site.pages << page
feeddata[month] = posts
end
feed = MonthlyFeed.new(site, feeddata)
site.pages << feed
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