From 01825f51db45826c61fc29ad9a380ece31e7623e Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Thu, 10 Dec 2020 19:30:23 +0530 Subject: [PATCH] Stash attribute hash for Liquid computed for pages (#8497) Merge pull request 8497 --- lib/jekyll/convertible.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index b9f7a93f..905afe57 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -112,11 +112,7 @@ module Jekyll # # Returns the Hash representation of this Convertible. def to_liquid(attrs = nil) - further_data = \ - (attrs || self.class::ATTRIBUTES_FOR_LIQUID).each_with_object({}) do |attribute, hsh| - hsh[attribute] = send(attribute) - end - + further_data = attribute_hash(attrs || self.class::ATTRIBUTES_FOR_LIQUID) Utils.deep_merge_hashes defaults, Utils.deep_merge_hashes(data, further_data) end @@ -250,6 +246,13 @@ 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