Skip to content

Commit

Permalink
site.collated_posts for use with archives.
Browse files Browse the repository at this point in the history
  • Loading branch information
henrik committed Apr 13, 2009
1 parent ad60114 commit 5ec47ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,21 @@ h3. Site

site.posts
A reverse chronological list of all Posts.

site.collated_posts
A nested hash by year, then month number, then day, then a list of Posts.
Suitable for post archives. You probably need to show these with Haml
since Liquid is too limited. For example:
- site.collated_posts.sort.reverse.each do |year,months|
%h2= year
- months.sort.reverse.each do |month,days|
%h3= Date::MONTHNAMES[month]
- days.sort.reverse.each do |day,posts|
%ol
- posts.each do |post|
%li
%strong= "#{day}:"
= link_to(h(post.title), post.url)

site.related_posts
If the page being processed is a Post, this contains a list of up to ten
Expand Down
6 changes: 5 additions & 1 deletion lib/jekyll/site.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Jekyll

class Site
attr_accessor :config, :layouts, :posts, :categories
attr_accessor :config, :layouts, :posts, :collated_posts, :categories
attr_accessor :source, :dest, :lsi, :pygments, :permalink_style, :permalink_date,
:sass, :post_defaults

Expand All @@ -27,6 +27,7 @@ def initialize(config)
def reset
self.layouts = {}
self.posts = []
self.collated_posts = Hash.new {|h,k| h[k] = Hash.new {|h,k| h[k] = Hash.new {|h,k| h[k] = [] } } }
self.categories = Hash.new { |hash, key| hash[key] = Array.new }
end

Expand Down Expand Up @@ -161,6 +162,9 @@ def read_posts(dir)
end

self.posts.sort!
self.posts.each do |post|
self.collated_posts[post.date.year][post.date.month][post.date.day].unshift(post)
end
self.categories.values.map { |cats| cats.sort! { |a, b| b <=> a} }
rescue Errno::ENOENT => e
# ignore missing layout dir
Expand Down

0 comments on commit 5ec47ed

Please sign in to comment.