add support for “sidecar” frontmatter at the destination url of proxied resources
a “cheap” way to support adding data to pages created through `proxy` or `page` by adding frontmatter at the expected destination url. for example proxying a page to `/proxied.html`, by adding a sidecar frontmatter file at `source/proxied.html.frontmatter` (or source/proxied.frontmatter if directory indexes is activated) the frontmatter will be merged with the proxy source and available to `current_resource` at the destination.
This commit is contained in:
parent
4a59ebefe3
commit
85fa3fac02
|
@ -149,3 +149,22 @@ Feature: Neighboring YAML Front Matter
|
|||
Then I should see "Layout in use: Override"
|
||||
When I go to "/page_mentioned.html.erb.frontmatter"
|
||||
Then I should see "File Not Found"
|
||||
|
||||
Scenario: Neighbor frontmatter for destination of proxy resources
|
||||
Given the Server is running at "frontmatter-settings-neighbor-app"
|
||||
And the file "source/proxied_with_frontmatter.html.frontmatter" has the contents
|
||||
"""
|
||||
---
|
||||
title: Proxied title
|
||||
---
|
||||
"""
|
||||
And the file "source/ignored.html.erb" has the contents
|
||||
"""
|
||||
---
|
||||
ignored: true
|
||||
---
|
||||
|
||||
<%= current_resource.data.title %>
|
||||
"""
|
||||
When I go to "/proxied_with_frontmatter.html"
|
||||
Then I should see "Proxied title"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# Proxy ignored.html, which should ignore itself through a frontmatter
|
||||
page 'proxied.html', :proxy => 'ignored.html'
|
||||
page 'proxied_with_frontmatter.html', :proxy => 'ignored.html'
|
||||
page 'override_layout.html', :layout => :alternate
|
||||
page 'page_mentioned.html'
|
||||
|
|
|
@ -61,7 +61,14 @@ module Middleman::CoreExtensions
|
|||
# @private
|
||||
# @return [Hash]
|
||||
def raw_data
|
||||
app.extensions[:frontmatter].data(source_file).first
|
||||
data = app.extensions[:frontmatter].data(source_file).first
|
||||
|
||||
if proxy?
|
||||
url_data = app.extensions[:frontmatter].data( File.join( app.source_dir, url ).chomp('/') ).first
|
||||
data = data.deep_merge(url_data)
|
||||
end
|
||||
|
||||
data
|
||||
end
|
||||
|
||||
# This page's frontmatter
|
||||
|
|
Loading…
Reference in a new issue