From eca450454f835bf7b3025618d5667a9b7a64bc4e Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Sun, 29 Aug 2021 12:52:42 +0530 Subject: [PATCH] Fix regression in Convertible module from v4.2.0 (#8786) Merge pull request 8786 --- features/rendering.feature | 32 ++++++++++++++++++++++++++++++++ lib/jekyll/convertible.rb | 13 +++++-------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/features/rendering.feature b/features/rendering.feature index dfce1920..2b504a07 100644 --- a/features/rendering.feature +++ b/features/rendering.feature @@ -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\": \"

about.md

" in "_site/test.json" + And I should see "content\": \"

Hello World

" in "_site/test.json" diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index 905afe57..b9f7a93f 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -112,7 +112,11 @@ module Jekyll # # 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 @@ -246,13 +250,6 @@ module Jekyll @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