-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aed80d7
commit 5f60f98
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
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
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 |
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
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 %} |