Skip to content
Permalink
Browse files

test generators with github

  • Loading branch information...
MichaelBitard committed Apr 2, 2015
1 parent aed80d7 commit 5f60f98cac273ee53dc4b458a06ba9e668f054b7
Showing with 35 additions and 0 deletions.
  1. +23 −0 _plugins/generators.rb
  2. +12 −0 archives/index.html
@@ -0,0 +1,23 @@
module Jekyll
class ArchivesGenerator < Generator
def generate(site)
years = {}
site.posts.each do |post|
if years.has_key?(post.date.year)
years[post.date.year] << {"url"=>post.url, "title"=>post.title}
else
years[post.date.year] = [{"url"=>post.url, "title"=>post.title}]
end
end

site.pages << ArchivesPage.new(site, site.source, "archives", "index.html", years)
end
end

class ArchivesPage < Page
def initialize(site, base, dir, name, years)
super(site, base, dir, name)
self.data['years'] = years
end
end
end
@@ -0,0 +1,12 @@
---
layout: default
---

{% for year in page.years %}
<h2>{{ year[0] }}</h2>
<ul>
{% for post in year[1] %}
<li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
</ul>
{% endfor %}

0 comments on commit 5f60f98

Please sign in to comment.
You can’t perform that action at this time.