Fix layout front-matter variables rendering. #6071 (#6073)

Merge pull request 6073
This commit is contained in:
Anatoliy Yastreb 2017-06-15 04:05:38 +09:00 committed by jekyllbot
parent c71c27a397
commit 2cfcb23a49
4 changed files with 18 additions and 0 deletions

View File

@ -54,6 +54,7 @@ module Jekyll
assign_pages!
assign_related_posts!
assign_highlighter_options!
assign_layout_data!
Jekyll.logger.debug "Pre-Render Hooks:", document.relative_path
document.trigger_hooks(:pre_render, payload)
@ -233,6 +234,14 @@ module Jekyll
payload["highlighter_suffix"] = converters.first.highlighter_suffix
end
private
def assign_layout_data!
layout = layouts[document.data["layout"]]
if layout
payload["layout"] = Utils.deep_merge_hashes(layout.data, payload["layout"] || {})
end
end
private
def permalink_ext
if document.permalink && !document.permalink.end_with?("/")

View File

@ -1,3 +1,6 @@
---
front_matter_var: variable from layout
---
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

View File

@ -5,6 +5,8 @@ title: Tom Preston-Werner
h1. Welcome to my site
{{ layout.front_matter_var }}
h2. Please read our {{ site.posts | size }} Posts
<ul>

View File

@ -21,6 +21,10 @@ class TestGeneratedSite < JekyllUnitTest
assert @index.include?("#{@site.posts.size} Posts")
end
should "insert variable from layout into the index" do
assert @index.include?("variable from layout")
end
should "render latest post's content" do
assert @index.include?(@site.posts.last.content)
end