From 9179f56ed7f17ee396335ca86b11d3b2cd14d15c Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 5 May 2013 14:59:50 +0200 Subject: [PATCH] Quick clean-up from #998. --- lib/jekyll/tags/post_url.rb | 19 ++++++++++++++++--- .../_posts/es/2008-11-21-nested.textile | 2 +- test/test_site.rb | 13 +++++++------ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/jekyll/tags/post_url.rb b/lib/jekyll/tags/post_url.rb index 6814c3ca..51b3b605 100644 --- a/lib/jekyll/tags/post_url.rb +++ b/lib/jekyll/tags/post_url.rb @@ -12,13 +12,26 @@ module Jekyll end def ==(other) - path = other.name.split("/")[0...-1].join("/") - otherslug = path != "" ? path + '/' + other.slug : other.slug - slug == otherslug && + slug == post_slug(other) && date.year == other.date.year && date.month == other.date.month && date.day == other.date.day end + + private + # Construct the directory-aware post slug for a Jekyll::Post + # + # other - the Jekyll::Post + # + # Returns the post slug with the subdirectory (relative to _posts) + def post_slug(other) + path = other.name.split("/")[0...-1].join("/") + if path.nil? || path == "" + other.slug + else + path + '/' + other.slug + end + end end class PostUrl < Liquid::Tag diff --git a/test/source/_posts/es/2008-11-21-nested.textile b/test/source/_posts/es/2008-11-21-nested.textile index 6140a46e..a0209ab7 100644 --- a/test/source/_posts/es/2008-11-21-nested.textile +++ b/test/source/_posts/es/2008-11-21-nested.textile @@ -5,4 +5,4 @@ title: Nested url: {{ page.url }} date: {{ page.date }} -id: {{ page.id }} \ No newline at end of file +id: {{ page.id }} diff --git a/test/test_site.rb b/test/test_site.rb index f59c0ea9..37fec83f 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -48,6 +48,7 @@ class TestSite < Test::Unit::TestCase Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir}) end @site = Site.new(Jekyll.configuration) + @num_invalid_posts = 2 end should "have an empty tag hash by default" do @@ -160,20 +161,20 @@ class TestSite < Test::Unit::TestCase should "read posts" do @site.read_posts('') - posts = Dir[source_dir('_posts', '*')] - posts.delete_if { |post| File.directory?(post) } - assert_equal posts.size, @site.posts.size + posts = Dir[source_dir('_posts', '**', '*')] + posts.delete_if { |post| File.directory?(post) && !Post.valid?(post) } + assert_equal posts.size - @num_invalid_posts, @site.posts.size end should "deploy payload" do clear_dest @site.process - posts = Dir[source_dir("**", "_posts", "*")] - posts.delete_if { |post| File.directory?(post) } + posts = Dir[source_dir("**", "_posts", "**", "*")] + posts.delete_if { |post| File.directory?(post) && !Post.valid?(post) } categories = %w(bar baz category foo z_category publish_test win).sort - assert_equal posts.size + 1, @site.posts.size + assert_equal posts.size - @num_invalid_posts, @site.posts.size assert_equal categories, @site.categories.keys.sort assert_equal 4, @site.categories['foo'].size end