From 85fa3fac02e1c6d68bfda0d1de87985dd3a0ac50 Mon Sep 17 00:00:00 2001 From: Steven Sloan Date: Mon, 22 Dec 2014 13:59:27 -0500 Subject: [PATCH] =?UTF-8?q?add=20support=20for=20=E2=80=9Csidecar=E2=80=9D?= =?UTF-8?q?=20frontmatter=20at=20the=20destination=20url=20of=20proxied=20?= =?UTF-8?q?resources?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../features/front-matter-neighbor.feature | 19 +++++++++++++++++++ .../config.rb | 1 + .../core_extensions/front_matter.rb | 9 ++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/middleman-core/features/front-matter-neighbor.feature b/middleman-core/features/front-matter-neighbor.feature index b420cba0..67eb3d16 100644 --- a/middleman-core/features/front-matter-neighbor.feature +++ b/middleman-core/features/front-matter-neighbor.feature @@ -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" diff --git a/middleman-core/fixtures/frontmatter-settings-neighbor-app/config.rb b/middleman-core/fixtures/frontmatter-settings-neighbor-app/config.rb index 74cda623..0285d071 100644 --- a/middleman-core/fixtures/frontmatter-settings-neighbor-app/config.rb +++ b/middleman-core/fixtures/frontmatter-settings-neighbor-app/config.rb @@ -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' diff --git a/middleman-core/lib/middleman-core/core_extensions/front_matter.rb b/middleman-core/lib/middleman-core/core_extensions/front_matter.rb index b7b099d3..4179fae0 100644 --- a/middleman-core/lib/middleman-core/core_extensions/front_matter.rb +++ b/middleman-core/lib/middleman-core/core_extensions/front_matter.rb @@ -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