Merge pull request #4110 from jekyll/subdirectories-arent-categories
Merge pull request 4110
This commit is contained in:
commit
5e790a6d49
|
@ -187,6 +187,24 @@ 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: Superdirectories of _posts applied to post.categories
|
||||||
|
Given I have a movies/_posts directory
|
||||||
|
And I have a "movies/_posts/2009-03-27-star-wars.html" page with layout "simple" that contains "hi"
|
||||||
|
And I have a _layouts directory
|
||||||
|
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/2009/03/27/star-wars.html"
|
||||||
|
|
||||||
|
Scenario: Subdirectories of _posts not applied to post.categories
|
||||||
|
Given I have a movies/_posts/scifi directory
|
||||||
|
And I have a "movies/_posts/scifi/2009-03-27-star-wars.html" page with layout "simple" that contains "hi"
|
||||||
|
And I have a _layouts directory
|
||||||
|
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/2009/03/27/star-wars.html"
|
||||||
|
|
||||||
Scenario: Use post.categories variable when categories are in YAML with mixed case
|
Scenario: Use post.categories variable when categories are in YAML with mixed case
|
||||||
Given I have a _posts directory
|
Given I have a _posts directory
|
||||||
And I have a _layouts directory
|
And I have a _layouts directory
|
||||||
|
|
|
@ -24,10 +24,11 @@ module Jekyll
|
||||||
@collection = relations[:collection]
|
@collection = relations[:collection]
|
||||||
@has_yaml_header = nil
|
@has_yaml_header = nil
|
||||||
|
|
||||||
subdirs = relative_path.split(File::SEPARATOR).reject do |c|
|
if draft?
|
||||||
c.empty? || c.eql?(collection.relative_directory) || c.eql?("_drafts") || c.eql?(basename)
|
categories_from_path("_drafts")
|
||||||
|
else
|
||||||
|
categories_from_path(collection.relative_directory)
|
||||||
end
|
end
|
||||||
merge_data!({'categories' => subdirs })
|
|
||||||
|
|
||||||
data.default_proc = proc do |hash, key|
|
data.default_proc = proc do |hash, key|
|
||||||
site.frontmatter_defaults.find(relative_path, collection.label, key)
|
site.frontmatter_defaults.find(relative_path, collection.label, key)
|
||||||
|
@ -75,6 +76,15 @@ module Jekyll
|
||||||
data['date'] ||= site.time
|
data['date'] ||= site.time
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns whether the document is a draft. This is only the case if
|
||||||
|
# the document is in the 'posts' collection but in a different
|
||||||
|
# directory than '_posts'.
|
||||||
|
#
|
||||||
|
# Returns whether the document is a draft.
|
||||||
|
def draft?
|
||||||
|
data['draft'] ||= relative_path.index(collection.relative_directory).nil? && collection.label == "posts"
|
||||||
|
end
|
||||||
|
|
||||||
# The path to the document, relative to the site source.
|
# The path to the document, relative to the site source.
|
||||||
#
|
#
|
||||||
# Returns a String path which represents the relative path
|
# Returns a String path which represents the relative path
|
||||||
|
@ -311,9 +321,21 @@ module Jekyll
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Add superdirectories of the special_dir to categories.
|
||||||
|
# In the case of es/_posts, 'es' is added as a category.
|
||||||
|
# In the case of _posts/es, 'es' is NOT added as a category.
|
||||||
|
#
|
||||||
|
# Returns nothing.
|
||||||
|
def categories_from_path(special_dir)
|
||||||
|
superdirs = relative_path.sub(/#{special_dir}(.*)/, '').split(File::SEPARATOR).reject do |c|
|
||||||
|
c.empty? || c.eql?(special_dir) || c.eql?(basename)
|
||||||
|
end
|
||||||
|
merge_data!({ 'categories' => superdirs })
|
||||||
|
end
|
||||||
|
|
||||||
def populate_categories
|
def populate_categories
|
||||||
merge_data!({
|
merge_data!({
|
||||||
"categories" => (
|
'categories' => (
|
||||||
Array(data['categories']) + Utils.pluralized_array_from_hash(data, 'category', 'categories')
|
Array(data['categories']) + Utils.pluralized_array_from_hash(data, 'category', 'categories')
|
||||||
).map { |c| c.to_s }.flatten.uniq
|
).map { |c| c.to_s }.flatten.uniq
|
||||||
})
|
})
|
||||||
|
|
|
@ -220,7 +220,7 @@ class TestSite < JekyllUnitTest
|
||||||
|
|
||||||
posts = Dir[source_dir("**", "_posts", "**", "*")]
|
posts = Dir[source_dir("**", "_posts", "**", "*")]
|
||||||
posts.delete_if { |post| File.directory?(post) && !(post =~ Document::DATE_FILENAME_MATCHER) }
|
posts.delete_if { |post| File.directory?(post) && !(post =~ Document::DATE_FILENAME_MATCHER) }
|
||||||
categories = %w(2013 bar baz category foo z_category MixedCase Mixedcase es publish_test win).sort
|
categories = %w(2013 bar baz category foo z_category MixedCase Mixedcase publish_test win).sort
|
||||||
|
|
||||||
assert_equal posts.size - @num_invalid_posts, @site.posts.size
|
assert_equal posts.size - @num_invalid_posts, @site.posts.size
|
||||||
assert_equal categories, @site.categories.keys.sort
|
assert_equal categories, @site.categories.keys.sort
|
||||||
|
|
|
@ -455,8 +455,8 @@ CONTENT
|
||||||
end
|
end
|
||||||
|
|
||||||
should "have the url to the \"nested\" post from 2008-11-21" do
|
should "have the url to the \"nested\" post from 2008-11-21" do
|
||||||
assert_match %r{3\s/es/2008/11/21/nested/}, @result
|
assert_match %r{3\s/2008/11/21/nested/}, @result
|
||||||
assert_match %r{4\s/es/2008/11/21/nested/}, @result
|
assert_match %r{4\s/2008/11/21/nested/}, @result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue