Skip to content

Commit

Permalink
Backport #8786 for v4.2.x (#8793)
Browse files Browse the repository at this point in the history
Fix regression in Convertible module from v4.2.0
This backports eca4504 to 4.2-stable
  • Loading branch information
ashmaroli committed Sep 16, 2021
1 parent ba024ea commit 54010a7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
32 changes: 32 additions & 0 deletions features/rendering.feature
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,35 @@ Feature: Rendering
And I should see "series named {{ site.title }}" in "_site/index.html"
And I should see "{% link series/first-part.md %}" in "_site/index.html"
And I should see "{% link series/last-part.md %}" in "_site/index.html"

Scenario: Render content of another page
Given I have an "index.md" page that contains "__Hello World__"
And I have an "about.md" page that contains "{{ page.name }}"
And I have a "test.json" file with content:
"""
---
---
{
"hpages": [
{%- for page in site.html_pages %}
{
"url" : {{ page.url | jsonify }},
"name" : {{ page.name | jsonify }},
"path" : {{ page.path | jsonify }},
"title" : {{ page.title | jsonify }},
"layout" : {{ page.layout | jsonify }},
"content": {{ page.content | jsonify }},
"excerpt": {{ page.excerpt | jsonify }}
}{% unless forloop.last %},{% endunless -%}
{% endfor %}
]
}
"""
When I run jekyll build
Then I should get a zero exit status
And the _site directory should exist
But I should not see "content\": \"{{ page.name }}" in "_site/test.json"
And I should not see "content\": \"__Hello World__" in "_site/test.json"
But I should see "content\": \"<p>about.md</p>" in "_site/test.json"
And I should see "content\": \"<p><strong>Hello World</strong></p>" in "_site/test.json"
13 changes: 5 additions & 8 deletions lib/jekyll/convertible.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ def render_liquid(content, payload, info, path)
#
# Returns the Hash representation of this Convertible.
def to_liquid(attrs = nil)
further_data = attribute_hash(attrs || self.class::ATTRIBUTES_FOR_LIQUID)
further_data = \
(attrs || self.class::ATTRIBUTES_FOR_LIQUID).each_with_object({}) do |attribute, hsh|
hsh[attribute] = send(attribute)
end

Utils.deep_merge_hashes defaults, Utils.deep_merge_hashes(data, further_data)
end

Expand Down Expand Up @@ -246,13 +250,6 @@ def defaults
@defaults ||= site.frontmatter_defaults.all(relative_path, type)
end

def attribute_hash(attrs)
@attribute_hash ||= {}
@attribute_hash[attrs] ||= attrs.each_with_object({}) do |attribute, hsh|
hsh[attribute] = send(attribute)
end
end

def no_layout?
data["layout"] == "none"
end
Expand Down

0 comments on commit 54010a7

Please sign in to comment.