From bac34fab3a27a12b35add1ecab409b19941e29a6 Mon Sep 17 00:00:00 2001 From: Josh Dady Date: Thu, 25 Dec 2008 13:49:56 -0500 Subject: [PATCH] Test and fix the site.categories hash --- lib/jekyll/site.rb | 11 ++++------- .../foo/_posts/bar/2008-12-12-topical-post.textile | 8 ++++++++ test/test_post.rb | 6 ++++++ test/test_site.rb | 7 +++++-- 4 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 test/source/foo/_posts/bar/2008-12-12-topical-post.textile diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 9c205431..8238b803 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -2,7 +2,7 @@ module Jekyll class Site attr_accessor :source, :dest - attr_accessor :layouts, :posts + attr_accessor :layouts, :posts, :categories # Initialize the site # +source+ is String path to the source directory containing @@ -16,6 +16,7 @@ module Jekyll self.dest = dest self.layouts = {} self.posts = [] + self.categories = Hash.new { |hash, key| hash[key] = Array.new } end # Do the actual work of processing the site and generating the @@ -63,6 +64,7 @@ module Jekyll if Post.valid?(f) post = Post.new(self.source, dir, f) self.posts << post + post.categories.each { |c| self.categories[c] << post } end end @@ -72,6 +74,7 @@ module Jekyll end self.posts.sort! + self.categories.values.map { |cats| cats.sort! { |a, b| b <=> a} } rescue Errno::ENOENT => e # ignore missing layout dir end @@ -133,12 +136,6 @@ module Jekyll # # Returns {"site" => {"time" =>