Skip to content

Commit

Permalink
test generators with github
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelBitard committed Apr 2, 2015
1 parent aed80d7 commit 5f60f98
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
23 changes: 23 additions & 0 deletions _plugins/generators.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions archives/index.html
Original file line number Diff line number Diff line change
@@ -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.