From e5403396b7db1264cc68b8a34d9275f1a1a8cec6 Mon Sep 17 00:00:00 2001 From: ashmaroli Date: Sun, 24 Sep 2017 01:33:40 +0530 Subject: [PATCH] Disable default layouts for Pages with a `layout: none` declaration (#6182) Merge pull request 6182 --- features/rendering.feature | 12 ++++++++---- lib/jekyll/convertible.rb | 10 ++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/features/rendering.feature b/features/rendering.feature index 1d9f2aa9..e6b80d9e 100644 --- a/features/rendering.feature +++ b/features/rendering.feature @@ -49,7 +49,7 @@ Feature: Rendering And I should not see "Ahoy, indeed!" in "_site/index.css" And I should not see "Ahoy, indeed!" in "_site/index.js" - Scenario: Ignore defaults and don't place documents with layout set to 'none' + Scenario: Ignore defaults and don't place pages and documents with layout set to 'none' Given I have a "index.md" page with layout "none" that contains "Hi there, {{ site.author }}!" And I have a _trials directory And I have a "_trials/no-layout.md" page with layout "none" that contains "Hi there, {{ site.author }}!" @@ -67,9 +67,11 @@ Feature: Rendering And I should not see "Welcome!" in "_site/trials/no-layout.html" And I should not see "Check this out!" in "_site/trials/no-layout.html" But I should see "Check this out!" in "_site/trials/test.html" - And I should see "Welcome!" in "_site/index.html" + And I should see "Hi there, John Doe!" in "_site/index.html" + And I should not see "Welcome!" in "_site/index.html" + And I should not see "Build Warning:" in the build output - Scenario: Don't place documents with layout set to 'none' + Scenario: Don't place pages and documents with layout set to 'none' Given I have a "index.md" page with layout "none" that contains "Hi there, {{ site.author }}!" And I have a _trials directory And I have a "_trials/no-layout.md" page with layout "none" that contains "Hi there, {{ site.author }}!" @@ -84,8 +86,10 @@ Feature: Rendering Then I should get a zero exit status And the _site directory should exist And I should not see "Welcome!" in "_site/trials/no-layout.html" + And I should not see "Welcome!" in "_site/index.html" But I should see "Check this out!" in "_site/trials/test.html" - And I should see "Welcome!" in "_site/index.html" + And I should see "Hi there, John Doe!" in "_site/index.html" + And I should not see "Build Warning:" in the build output Scenario: Render liquid in Sass Given I have an "index.scss" page that contains ".foo-bar { color:{{site.color}}; }" diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index 6b205482..45a83c4f 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -172,9 +172,10 @@ module Jekyll # Determine whether the file should be placed into layouts. # - # Returns false if the document is an asset file. + # Returns false if the document is an asset file or if the front matter + # specifies `layout: none` def place_in_layout? - !asset_file? + !(asset_file? || no_layout?) end # Checks if the layout specified in the document actually exists @@ -244,8 +245,13 @@ module Jekyll end private + def _renderer @_renderer ||= Jekyll::Renderer.new(site, self) end + + def no_layout? + data["layout"] == "none" + end end end