Merge pull request #2633 from redox/read_categories_from_path
This commit is contained in:
commit
18c033dc5c
|
@ -159,6 +159,8 @@ module Jekyll
|
|||
# Returns nothing.
|
||||
def process(name)
|
||||
m, cats, date, slug, ext = *name.match(MATCHER)
|
||||
self.categories ||= []
|
||||
self.categories += (cats || '').downcase.split('/')
|
||||
self.date = Time.parse(date)
|
||||
self.slug = slug
|
||||
self.ext = ext
|
||||
|
|
|
@ -76,6 +76,21 @@ class TestPost < Test::Unit::TestCase
|
|||
assert_equal "/2008/09/09/foo-bar", @post.id
|
||||
end
|
||||
|
||||
should "keep categories" do
|
||||
post = Post.allocate
|
||||
post.site = @site
|
||||
post.process("cat1/2008-09-09-foo-bar.textile")
|
||||
assert_equal 1, post.categories.size
|
||||
assert_equal "cat1", post.categories[0]
|
||||
|
||||
post = Post.allocate
|
||||
post.site = @site
|
||||
post.process("cat2/CAT3/2008-09-09-foo-bar.textile")
|
||||
assert_equal 2, post.categories.size
|
||||
assert_equal "cat2", post.categories[0]
|
||||
assert_equal "cat3", post.categories[1]
|
||||
end
|
||||
|
||||
should "create url based on date and title" do
|
||||
@post.categories = []
|
||||
@post.process(@fake_file)
|
||||
|
@ -615,7 +630,7 @@ class TestPost < Test::Unit::TestCase
|
|||
|
||||
should "generate categories and topics" do
|
||||
post = Post.new(@site, File.join(File.dirname(__FILE__), *%w[source]), 'foo', 'bar/2008-12-12-topical-post.textile')
|
||||
assert_equal ['foo'], post.categories
|
||||
assert_equal ['foo', 'bar'], post.categories
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -212,7 +212,7 @@ class TestSite < Test::Unit::TestCase
|
|||
|
||||
posts = Dir[source_dir("**", "_posts", "**", "*")]
|
||||
posts.delete_if { |post| File.directory?(post) && !Post.valid?(post) }
|
||||
categories = %w(2013 bar baz category foo z_category publish_test win).sort
|
||||
categories = %w(2013 bar baz category es foo z_category publish_test win).sort
|
||||
|
||||
assert_equal posts.size - @num_invalid_posts, @site.posts.size
|
||||
assert_equal categories, @site.categories.keys.sort
|
||||
|
|
|
@ -244,8 +244,8 @@ CONTENT
|
|||
end
|
||||
|
||||
should "have the url to the \"nested\" post from 2008-11-21" do
|
||||
assert_match %r{3\s/2008/11/21/nested/}, @result
|
||||
assert_match %r{4\s/2008/11/21/nested/}, @result
|
||||
assert_match %r{3\s/es/2008/11/21/nested/}, @result
|
||||
assert_match %r{4\s/es/2008/11/21/nested/}, @result
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue