Permalink
Browse files

site.collated_posts for use with archives.

  • Loading branch information...
1 parent ad60114 commit 5ec47edbc2c9006edde032a80f9f341cd74f3f40 @henrik henrik committed Apr 13, 2009
Showing with 20 additions and 1 deletion.
  1. +15 −0 README.textile
  2. +5 −1 lib/jekyll/site.rb
View
@@ -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
View
@@ -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
@@ -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
@@ -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

0 comments on commit 5ec47ed

Please sign in to comment.