Merge pull request #2531 from jekyll/merge-post-categories

This commit is contained in:
Parker Moore 2014-06-23 18:58:51 -04:00
commit e58c1ee306
3 changed files with 17 additions and 6 deletions

View File

@ -70,6 +70,18 @@ Feature: Post data
Then the _site directory should exist Then the _site directory should exist
And I should see "Post category: movies" in "_site/movies/2009/03/27/star-wars.html" And I should see "Post category: movies" in "_site/movies/2009/03/27/star-wars.html"
Scenario: Use post.categories variable when category is in a folder and has categories in YAML
Given I have a movies directory
And I have a movies/_posts directory
And I have a _layouts directory
And I have the following post in "movies":
| title | date | layout | categories | content |
| Star Wars | 2009-03-27 | simple | [film] | Luke, I am your father. |
And I have a simple layout that contains "Post category: {{ page.categories }}"
When I run jekyll build
Then the _site directory should exist
And I should see "Post category: movies" in "_site/movies/film/2009/03/27/star-wars.html"
Scenario: Use post.tags variable Scenario: Use post.tags variable
Given I have a _posts directory Given I have a _posts directory
And I have a _layouts directory And I have a _layouts directory

View File

@ -77,9 +77,8 @@ module Jekyll
end end
def populate_categories def populate_categories
if categories.empty? categories_from_data = Utils.pluralized_array_from_hash(data, 'category', 'categories')
self.categories = Utils.pluralized_array_from_hash(data, 'category', 'categories').map {|c| c.to_s.downcase} self.categories = (Array(categories) + categories_from_data).map {|c| c.to_s.downcase}
end
categories.flatten! categories.flatten!
end end

View File

@ -666,7 +666,7 @@ class TestPost < Test::Unit::TestCase
end end
end end
context "site config with category" do context "site config with category" do
setup do setup do
config = Jekyll::Configuration::DEFAULTS.merge({ config = Jekyll::Configuration::DEFAULTS.merge({
@ -686,7 +686,7 @@ class TestPost < Test::Unit::TestCase
post = setup_post("2009-01-27-no-category.textile") post = setup_post("2009-01-27-no-category.textile")
assert post.categories.include?('article'), "Expected post.categories to include 'article' but did not." assert post.categories.include?('article'), "Expected post.categories to include 'article' but did not."
end end
should "override site category if set on post" do should "override site category if set on post" do
post = setup_post("2009-01-27-category.textile") post = setup_post("2009-01-27-category.textile")
assert post.categories.include?('foo'), "Expected post.categories to include 'foo' but did not." assert post.categories.include?('foo'), "Expected post.categories to include 'foo' but did not."
@ -713,7 +713,7 @@ class TestPost < Test::Unit::TestCase
post = setup_post("2009-01-27-no-category.textile") post = setup_post("2009-01-27-no-category.textile")
assert post.categories.include?('article'), "Expected post.categories to include 'article' but did not." assert post.categories.include?('article'), "Expected post.categories to include 'article' but did not."
end end
should "override site categories if set on post" do should "override site categories if set on post" do
post = setup_post("2009-01-27-categories.textile") post = setup_post("2009-01-27-categories.textile")
['foo', 'bar', 'baz'].each do |category| ['foo', 'bar', 'baz'].each do |category|