From 74581422e3dbdf754ee519386d59db4e3c73f28f Mon Sep 17 00:00:00 2001 From: Kyle Barbour Date: Thu, 17 May 2018 15:22:32 -0700 Subject: [PATCH 1/5] Add whitespace control to LIQUID_TAG_REGEX (#7015) Merge pull request 7015 --- lib/jekyll/excerpt.rb | 9 +++- ...liquid-block-excerpt-whitespace-control.md | 9 ++++ ...-15-excerpt-whitespace-control-variable.md | 7 +++ ...liquid-block-excerpt-whitespace-control.md | 10 ++++ test/test_excerpt.rb | 52 +++++++++++++++++++ test/test_generated_site.rb | 2 +- 6 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 test/source/_posts/2018-05-15-closed-liquid-block-excerpt-whitespace-control.md create mode 100644 test/source/_posts/2018-05-15-excerpt-whitespace-control-variable.md create mode 100644 test/source/_posts/2018-05-15-open-liquid-block-excerpt-whitespace-control.md diff --git a/lib/jekyll/excerpt.rb b/lib/jekyll/excerpt.rb index d270624c..1df15e09 100644 --- a/lib/jekyll/excerpt.rb +++ b/lib/jekyll/excerpt.rb @@ -128,7 +128,7 @@ module Jekyll # # Returns excerpt String - LIQUID_TAG_REGEX = %r!{%\s*(\w+).+\s*%}!m + LIQUID_TAG_REGEX = %r!{%-?\s*(\w+).+\s*-?%}!m MKDWN_LINK_REF_REGEX = %r!^ {0,3}\[[^\]]+\]:.+$! def extract_excerpt(doc_content) @@ -141,7 +141,7 @@ module Jekyll head =~ LIQUID_TAG_REGEX tag_name = Regexp.last_match(1) - if liquid_block?(tag_name) && head.match(%r!{%\s*end#{tag_name}\s*%}!).nil? + if liquid_block?(tag_name) && head.match(%r!{%-?\s*end#{tag_name}\s*-?%}!).nil? print_build_warning head << "\n{% end#{tag_name} %}" end @@ -158,6 +158,11 @@ module Jekyll def liquid_block?(tag_name) Liquid::Template.tags[tag_name].superclass == Liquid::Block + rescue NoMethodError + Jekyll.logger.error "Error:", + "A Liquid tag in the excerpt of #{doc.relative_path} couldn't be " \ + "parsed." + raise end def print_build_warning diff --git a/test/source/_posts/2018-05-15-closed-liquid-block-excerpt-whitespace-control.md b/test/source/_posts/2018-05-15-closed-liquid-block-excerpt-whitespace-control.md new file mode 100644 index 00000000..c4355924 --- /dev/null +++ b/test/source/_posts/2018-05-15-closed-liquid-block-excerpt-whitespace-control.md @@ -0,0 +1,9 @@ +--- +title: LIQUID_TAG_REGEX excerpt whitespace control test +layout: post +--- + +{%- for post in site.posts -%} + You are in a maze of twisty little passages, all alike. + There's lots more to say about this, but that's enough for now. +{%- endfor -%} diff --git a/test/source/_posts/2018-05-15-excerpt-whitespace-control-variable.md b/test/source/_posts/2018-05-15-excerpt-whitespace-control-variable.md new file mode 100644 index 00000000..aad1207a --- /dev/null +++ b/test/source/_posts/2018-05-15-excerpt-whitespace-control-variable.md @@ -0,0 +1,7 @@ +--- +title: LIQUID_TAG_REGEX excerpt whitespace control test +layout: post +--- + +{%- assign xyzzy = 'You are in a maze of twisty little passages, all alike.' %} +{{- xyzzy -}} diff --git a/test/source/_posts/2018-05-15-open-liquid-block-excerpt-whitespace-control.md b/test/source/_posts/2018-05-15-open-liquid-block-excerpt-whitespace-control.md new file mode 100644 index 00000000..4ed79958 --- /dev/null +++ b/test/source/_posts/2018-05-15-open-liquid-block-excerpt-whitespace-control.md @@ -0,0 +1,10 @@ +--- +title: LIQUID_TAG_REGEX excerpt whitespace control test +layout: post +--- + +{%- for post in site.posts -%} + You are in a maze of twisty little passages, all alike. + + There's lots more to say about this, but that's enough for now. +{%- endfor -%} diff --git a/test/test_excerpt.rb b/test/test_excerpt.rb index c4b4538d..24647dec 100644 --- a/test/test_excerpt.rb +++ b/test/test_excerpt.rb @@ -212,4 +212,56 @@ class TestExcerpt < JekyllUnitTest assert_equal true, @excerpt.is_a?(Jekyll::Excerpt) end end + + context "An excerpt with non-closed but valid Liquid block tag with whitespace control" do + setup do + clear_dest + @site = fixture_site + @post = setup_post("2018-05-15-open-liquid-block-excerpt-whitespace-control.md") + @excerpt = @post.data["excerpt"] + + assert_includes @post.content, "{%- for" + refute_includes @post.content.split("\n\n")[0], "{%- endfor -%}" + end + + should "be appended to as necessary and generated" do + assert_includes @excerpt.content, "{% endfor %}" + refute_includes @excerpt.content, "{% endfor %}\n\n{% endfor %}" + assert_equal true, @excerpt.is_a?(Jekyll::Excerpt) + end + end + + context "An excerpt with valid closed Liquid block tag with whitespace control" do + setup do + clear_dest + @site = fixture_site + @post = setup_post("2018-05-15-closed-liquid-block-excerpt-whitespace-control.md") + @excerpt = @post.data["excerpt"] + + assert_includes @post.content, "{%- for" + assert_includes @post.content.split("\n\n")[0], "{%- endfor -%}" + end + + should "not be appended to but generated as is" do + assert_includes @excerpt.content, "{%- endfor -%}" + refute_includes @excerpt.content, "{% endfor %}\n\n{% endfor %}" + assert_equal true, @excerpt.is_a?(Jekyll::Excerpt) + end + end + + context "An excerpt with valid Liquid variable with whitespace control" do + setup do + clear_dest + @site = fixture_site + @post = setup_post("2018-05-15-excerpt-whitespace-control-variable.md") + @excerpt = @post.data["excerpt"] + + assert_includes @post.content, "{%- assign" + end + + should "not be appended to but generated as is" do + assert_includes @excerpt.content, "{{- xyzzy -}}" + assert_equal true, @excerpt.is_a?(Jekyll::Excerpt) + end + end end diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb index 4eaddb29..7ce09353 100644 --- a/test/test_generated_site.rb +++ b/test/test_generated_site.rb @@ -16,7 +16,7 @@ class TestGeneratedSite < JekyllUnitTest end should "ensure post count is as expected" do - assert_equal 54, @site.posts.size + assert_equal 57, @site.posts.size end should "insert site.posts into the index" do From b18872b658528b725825fd2911e84468bbd21908 Mon Sep 17 00:00:00 2001 From: jekyllbot Date: Thu, 17 May 2018 18:22:33 -0400 Subject: [PATCH 2/5] Update history to reflect merge of #7015 [ci skip] --- History.markdown | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/History.markdown b/History.markdown index 5cef9fef..1333ff19 100644 --- a/History.markdown +++ b/History.markdown @@ -1,3 +1,9 @@ +## HEAD + +### Bug Fixes + + * Add whitespace control to LIQUID_TAG_REGEX (#7015) + ## 3.8.1 / 2018-05-01 ### Bug Fixes From 450da91b4b0c0f25868f6492cbc0c3db257dba90 Mon Sep 17 00:00:00 2001 From: Nikita Skalkin Date: Tue, 15 May 2018 22:37:05 +0300 Subject: [PATCH 3/5] Update rubocop version (#7016) Merge pull request 7016 --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index c20ea234..af7e2190 100644 --- a/Gemfile +++ b/Gemfile @@ -31,7 +31,7 @@ group :test do gem "nokogiri", RUBY_VERSION >= "2.2" ? "~> 1.7" : "~> 1.7.0" gem "rspec" gem "rspec-mocks" - gem "rubocop", "~> 0.55.0" + gem "rubocop", "~> 0.56.0" gem "test-dependency-theme", :path => File.expand_path("test/fixtures/test-dependency-theme", __dir__) gem "test-theme", :path => File.expand_path("test/fixtures/test-theme", __dir__) From b89efa5d5d6a5f7284bf91370a8e759b99d17b5c Mon Sep 17 00:00:00 2001 From: jekyllbot Date: Tue, 15 May 2018 15:37:08 -0400 Subject: [PATCH 4/5] Update history to reflect merge of #7016 [ci skip] --- History.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/History.markdown b/History.markdown index 1333ff19..6ddf11c3 100644 --- a/History.markdown +++ b/History.markdown @@ -1,5 +1,9 @@ ## HEAD +### Development Fixes + + * Update rubocop version (#7016) + ### Bug Fixes * Add whitespace control to LIQUID_TAG_REGEX (#7015) From d22b8ee3920c28a1a540462d931896eaf695f33c Mon Sep 17 00:00:00 2001 From: Pat Hawks Date: Sat, 19 May 2018 10:30:00 -0500 Subject: [PATCH 5/5] Release :gem: 3.8.2 --- History.markdown | 2 +- docs/_config.yml | 2 +- docs/_docs/history.md | 14 ++++++++++++++ .../2018-05-18-jekyll-3-8-2-released.markdown | 19 +++++++++++++++++++ docs/latest_version.txt | 2 +- lib/jekyll/version.rb | 2 +- 6 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 docs/_posts/2018-05-18-jekyll-3-8-2-released.markdown diff --git a/History.markdown b/History.markdown index 6ddf11c3..64f743f5 100644 --- a/History.markdown +++ b/History.markdown @@ -1,4 +1,4 @@ -## HEAD +## 3.8.2 / 2018-05-18 ### Development Fixes diff --git a/docs/_config.yml b/docs/_config.yml index 4084cdd6..e608b1b6 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1,5 +1,5 @@ --- -version: 3.8.1 +version: 3.8.2 name: Jekyll • Simple, blog-aware, static sites description: Transform your plain text into static websites and blogs url: https://jekyllrb.com diff --git a/docs/_docs/history.md b/docs/_docs/history.md index e30472b2..4a9faf7f 100644 --- a/docs/_docs/history.md +++ b/docs/_docs/history.md @@ -4,6 +4,20 @@ permalink: "/docs/history/" note: This file is autogenerated. Edit /History.markdown instead. --- +## 3.8.2 / 2018-05-18 +{: #v3-8-2} + +### Development Fixes +{: #development-fixes-v3-8-2} + +- Update rubocop version ([#7016]({{ site.repository }}/issues/7016)) + +### Bug Fixes +{: #bug-fixes-v3-8-2} + +- Add whitespace control to LIQUID_TAG_REGEX ([#7015]({{ site.repository }}/issues/7015)) + + ## 3.8.1 / 2018-05-01 {: #v3-8-1} diff --git a/docs/_posts/2018-05-18-jekyll-3-8-2-released.markdown b/docs/_posts/2018-05-18-jekyll-3-8-2-released.markdown new file mode 100644 index 00000000..7d964e86 --- /dev/null +++ b/docs/_posts/2018-05-18-jekyll-3-8-2-released.markdown @@ -0,0 +1,19 @@ +--- +title: 'Jekyll 3.8.2 Released' +date: 2018-05-19 10:30:00 -0500 +author: pathawks +version: 3.8.2 +categories: [release] +--- + +Hello Jekyllers!! + +Today we are releasing `v3.8.2`, which fixes the way Jekyll generates excerpts +for posts when the first paragraph of the post contains Liquid tags that take +advantage of [Liquid's whitespace control feature][Liquid whitespace]. + +Big thanks to @kylebarbour, who first reported this issue and also very quickly +submitted a fix. Also thanks to @nickskalkin for making sure that we are using +the latest version of Rubocop to lint our code. + +[Liquid whitespace]: https://shopify.github.io/liquid/basics/whitespace/ diff --git a/docs/latest_version.txt b/docs/latest_version.txt index f2807196..a08ffae0 100644 --- a/docs/latest_version.txt +++ b/docs/latest_version.txt @@ -1 +1 @@ -3.8.1 +3.8.2 diff --git a/lib/jekyll/version.rb b/lib/jekyll/version.rb index f958b6af..0a6a8a2d 100644 --- a/lib/jekyll/version.rb +++ b/lib/jekyll/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Jekyll - VERSION = "3.8.1".freeze + VERSION = "3.8.2".freeze end