From 0e8f2040113fd4ca49ca138925f6c01f9e7197b0 Mon Sep 17 00:00:00 2001 From: Marko Locher Date: Sat, 7 May 2016 16:58:44 +0200 Subject: [PATCH 1/3] Fix #3926 post_url helper with sub-directories Instead of matching the the value provided to `post_url` against the basename, test against the relative path. Updated the regexp to match both * _posts/category * category/_posts --- lib/jekyll/tags/post_url.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/tags/post_url.rb b/lib/jekyll/tags/post_url.rb index 04c1ef29..c8b820b8 100644 --- a/lib/jekyll/tags/post_url.rb +++ b/lib/jekyll/tags/post_url.rb @@ -14,7 +14,7 @@ module Jekyll "'#{name}' does not contain valid date and/or title." end - @name_regex = %r!^#{path}#{date}-#{slug}\.[^.]+! + @name_regex = %r!^_posts/#{path}#{date}-#{slug}\.[^.]+|^#{path}_posts/?#{date}-#{slug}\.[^.]+! end def post_date @@ -23,7 +23,7 @@ module Jekyll end def ==(other) - other.basename.match(@name_regex) + other.relative_path.match(@name_regex) end def deprecated_equality(other) From 49e97ef9b01831e747f1466452f527cc4bcb9aa6 Mon Sep 17 00:00:00 2001 From: Marko Locher Date: Wed, 18 May 2016 14:29:51 +0200 Subject: [PATCH 2/3] Add test case for deprecated post comparison Checks that `post_url` works for nested posts even if the path isn't specified. Also checks that a deprecation message is shown in the build log. --- test/test_tags.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/test_tags.rb b/test/test_tags.rb index 6b8fe8db..5bfbd2f8 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -587,6 +587,32 @@ CONTENT end end + context "simple page with nested post linking and path not used in `post_url`" do + setup do + content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) + end + + should "not cause an error" do + refute_match(/markdown\-html\-error/, @result) + end + + should "have the url to the \"nested\" post from 2008-11-21" do + assert_match %r{1\s/2008/11/21/nested/}, @result + end + + should "throw a deprecation warning" do + deprecation_warning = " Deprecation: A call to '{{ post_url 2008-11-21-nested }}' did not match a post using the new matching method of checking name (path-date-slug) equality. Please make sure that you change this tag to match the post's name exactly." + assert_includes Jekyll.logger.messages, deprecation_warning + end + end + context "simple page with invalid post name linking" do should "cause an error" do content = < Date: Thu, 14 Jul 2016 12:15:00 +0200 Subject: [PATCH 3/3] Fix Rubocop warnings --- lib/jekyll/tags/post_url.rb | 3 ++- test/test_tags.rb | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/jekyll/tags/post_url.rb b/lib/jekyll/tags/post_url.rb index c8b820b8..b865cd67 100644 --- a/lib/jekyll/tags/post_url.rb +++ b/lib/jekyll/tags/post_url.rb @@ -14,7 +14,8 @@ module Jekyll "'#{name}' does not contain valid date and/or title." end - @name_regex = %r!^_posts/#{path}#{date}-#{slug}\.[^.]+|^#{path}_posts/?#{date}-#{slug}\.[^.]+! + @name_regex = %r!^_posts/#{path}#{date}-#{slug}\.[^.]+| + ^#{path}_posts/?#{date}-#{slug}\.[^.]+!x end def post_date diff --git a/test/test_tags.rb b/test/test_tags.rb index 5bfbd2f8..7a929281 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -596,19 +596,27 @@ title: Deprecated Post linking - 1 {% post_url 2008-11-21-nested %} CONTENT - create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) + create_post(content, { + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true + }) end should "not cause an error" do - refute_match(/markdown\-html\-error/, @result) + refute_match(%r!markdown\-html\-error!, @result) end should "have the url to the \"nested\" post from 2008-11-21" do - assert_match %r{1\s/2008/11/21/nested/}, @result + assert_match %r!1\s/2008/11/21/nested/!, @result end should "throw a deprecation warning" do - deprecation_warning = " Deprecation: A call to '{{ post_url 2008-11-21-nested }}' did not match a post using the new matching method of checking name (path-date-slug) equality. Please make sure that you change this tag to match the post's name exactly." + deprecation_warning = " Deprecation: A call to "\ + "'{{ post_url 2008-11-21-nested }}' did not match a post using the new matching "\ + "method of checking name (path-date-slug) equality. Please make sure that you "\ + "change this tag to match the post's name exactly." assert_includes Jekyll.logger.messages, deprecation_warning end end