Created
November 20, 2010 15:44
-
-
Save ilkka/707909 to your computer and use it in GitHub Desktop.
Jekyll archive page generator plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "#{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
@nlindley This is a simple question, but when I run 'jekyll build' the file loads but none of the methods are ever called. The file is in my _layouts folder, and I know it's getting loaded, but none of the methods fire. Any ideas?