Disable Liquid via front matter (#6824)

Merge pull request 6824
This commit is contained in:
Pat Hawks 2018-07-13 11:12:49 -05:00 committed by jekyllbot
parent b69196cad3
commit 7a4b3fe03d
5 changed files with 26 additions and 0 deletions

View File

@ -251,6 +251,19 @@ Feature: Post data
And I should see "Post categories: scifi and Movies" in "_site/scifi/movies/2009/03/27/star-wars.html"
And I should see "Post categories: SciFi and movies" in "_site/scifi/movies/2013/03/17/star-trek.html"
Scenario: Use page.render_with_liquid variable
Given I have a _posts directory
And I have the following posts:
| title | render_with_liquid | date | content |
| Unrendered Post | false | 2017-07-06 | Hello {{ page.title }} |
| Rendered Post | true | 2017-07-06 | Hello {{ page.title }} |
When I run jekyll build
Then I should get a zero exit status
And the _site directory should exist
And I should not see "Hello Unrendered Post" in "_site/2017/07/06/unrendered-post.html"
But I should see "Hello {{ page.title }}" in "_site/2017/07/06/unrendered-post.html"
And I should see "Hello Rendered Post" in "_site/2017/07/06/rendered-post.html"
Scenario Outline: Use page.path variable
Given I have a <dir>/_posts directory
And I have the following post in "<dir>":

View File

@ -160,6 +160,7 @@ module Jekyll
#
# Returns true if the file has Liquid Tags or Variables, false otherwise.
def render_with_liquid?
return false if data["render_with_liquid"] == false
Jekyll::Utils.has_liquid_construct?(content)
end

View File

@ -159,6 +159,7 @@ module Jekyll
# or if the document doesn't contain any Liquid Tags or Variables,
# true otherwise.
def render_with_liquid?
return false if data["render_with_liquid"] == false
!(coffeescript_file? || yaml_file? || !Utils.has_liquid_construct?(content))
end

4
test/fixtures/no_liquid.erb vendored Normal file
View File

@ -0,0 +1,4 @@
---
render_with_liquid: false
---
{% raw %}{% endraw %}

View File

@ -73,5 +73,12 @@ class TestConvertible < JekyllUnitTest
end
refute_match(%r!Invalid permalink!, out)
end
should "not parse Liquid if disabled in front matter" do
name = "no_liquid.erb"
@convertible.read_yaml(@base, name)
ret = @convertible.content.strip
assert_equal("{% raw %}{% endraw %}", ret)
end
end
end