diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 0e2af904..7d2bcad5 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -49,7 +49,13 @@ module Jekyll if self.data.has_key?('category') self.categories << self.data['category'] elsif self.data.has_key?('categories') - self.categories = self.data['categories'].split + # Look for categories in the YAML-header, either specified as + # an array or a string. + if self.data['categories'].kind_of? String + self.categories = self.data['categories'].split + else + self.categories = self.data['categories'] + end end end end diff --git a/test/source/_posts/2009-01-27-array-categories.textile b/test/source/_posts/2009-01-27-array-categories.textile new file mode 100644 index 00000000..575843d6 --- /dev/null +++ b/test/source/_posts/2009-01-27-array-categories.textile @@ -0,0 +1,10 @@ +--- +layout: default +title: Array categories in YAML +categories: +- foo +- bar +- baz +--- + +Best *post* ever diff --git a/test/test_post.rb b/test/test_post.rb index 0a118df3..4627d43c 100644 --- a/test/test_post.rb +++ b/test/test_post.rb @@ -87,10 +87,16 @@ class TestPost < Test::Unit::TestCase end def test_yaml_categories - p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', "2009-01-27-categories.textile") - assert p.categories.include?('foo') - assert p.categories.include?('bar') - assert p.categories.include?('baz') + p1 = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', + "2009-01-27-categories.textile") + p2 = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', + "2009-01-27-array-categories.textile") + + [p1, p2].each do |p| + assert p.categories.include?('foo') + assert p.categories.include?('bar') + assert p.categories.include?('baz') + end end def test_render