diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 97b7b677..e171d090 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 diff --git a/test/source/foo/_posts/bar/2008-12-12-topical-post.textile b/test/source/foo/_posts/bar/2008-12-12-topical-post.textile new file mode 100644 index 00000000..813db112 --- /dev/null +++ b/test/source/foo/_posts/bar/2008-12-12-topical-post.textile @@ -0,0 +1,8 @@ +--- +layout: default +title: Topical Post +--- + +h1. {{ page.title }} + +This post has a topic. diff --git a/test/test_post.rb b/test/test_post.rb index 9ff73bae..713eec02 100644 --- a/test/test_post.rb +++ b/test/test_post.rb @@ -96,6 +96,12 @@ class TestPost < Test::Unit::TestCase assert_equal "<<<

url: /2008/11/21/complex.html
\ndate: #{Time.parse("2008-11-21")}
\nid: /2008/11/21/complex

>>>", p.output end + def test_categories_and_topics + p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), 'foo', 'bar/2008-12-12-topical-post.textile') + assert_equal ['foo'], p.categories + assert_equal ['bar'], p.topics + end + def test_include Jekyll.source = File.join(File.dirname(__FILE__), *%w[source]) p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', "2008-12-13-include.markdown") diff --git a/test/test_site.rb b/test/test_site.rb index 52c1ca83..fa256177 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -22,9 +22,12 @@ class TestSite < Test::Unit::TestCase assert_equal 4, @s.posts.size end - def test_write_posts + def test_site_payload clear_dest - @s.process + + assert_equal 5, @s.posts.length + assert_equal ['foo'], @s.categories.keys + assert_equal 1, @s.categories['foo'].length end end