public
Last active

Jekyll archive page generator plugin

  • Download Gist
archivegenerator.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
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

WIth newest jekyll, getting a couple of errors with these:

Warning: Command failed: error: undefined method `destination' for #<Jekyll::ArchivePage:0x007fde91191618>. Use --trace to view backtrace
Generating... Warning: Command failed: error: undefined method `uses_relative_permalinks' for #<Jekyll::ArchivePage:0x007f99bce18a40>. Use --trace to view backtrace

jekyll version 1.0.3, ruby version 1.9.2-p320

Any ideas? I added these as accessors to the ArchivePage, but then ended up with a different error:

Warning: Command failed: error: wrong number of arguments (1 for 0). Use --trace to view backtrace
 Use --force to continue.

@ikka the same is true with ruby 1.9.3

I have this output too with ruby 1.9.3 and latest jekyll.

The default year/month format doesn’t match Jekyll’s because the months aren’t getting zero-padded. You can see my fix here: https://gist.github.com/nlindley/6409441

To those having problems with the warning, having ArchivePage inherit Page seems to fix the issues. See this gist: https://gist.github.com/nlindley/6409459

@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?

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.