From 651b9b5593ce1485a4ded98fa758cec5120004e9 Mon Sep 17 00:00:00 2001 From: ashmaroli Date: Thu, 12 Apr 2018 21:04:55 +0530 Subject: [PATCH] `include_relative` tag should find related documents in collections gathered within custom `collections_dir` (#6818) Merge pull request 6818 --- features/collections_dir.feature | 48 ++++++++++++++++++++++++++++++++ lib/jekyll/tags/include.rb | 11 ++++++-- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/features/collections_dir.feature b/features/collections_dir.feature index 9572f568..a8c15913 100644 --- a/features/collections_dir.feature +++ b/features/collections_dir.feature @@ -159,3 +159,51 @@ Feature: Collections Directory And I should see exactly "Nested Static content." in "_site/puppies/nested/static_file.txt" And the _site/gathering directory should not exist And the _site/_posts directory should not exist + + Scenario: Rendered collection with a document that includes a relative document + Given I have a _puppies directory + And I have the following documents under the puppies collection: + | title | date | content | + | INTRO | 2007-12-31 | excerpt for all docs. | + | Rover | 2007-12-31 | {% include_relative intro.md %} | + And I have a _posts directory + And I have the following post: + | title | date | content | + | Gathered Post | 2009-03-27 | Random Content. | + And I have a "_config.yml" file with content: + """ + collections: + puppies: + output: true + """ + When I run jekyll build + Then I should get a zero exit status + And the _site directory should exist + And the "_site/puppies/rover.html" file should exist + And I should see "excerpt for all docs." in "_site/puppies/rover.html" + And I should see "Random Content." in "_site/2009/03/27/gathered-post.html" + + Scenario: Rendered collection in custom collections_dir with a document that includes a relative document + Given I have a collections/_puppies directory + And I have the following documents under the "puppies" collection within the "collections" directory: + | title | date | content | + | INTRO | 2007-12-31 | excerpt for all docs. | + | Rover | 2007-12-31 | {% include_relative intro.md %} | + And I have a collections/_posts directory + And I have the following post within the "collections" directory: + | title | date | content | + | Gathered Post | 2009-03-27 | Random Content. | + And I have a "_config.yml" file with content: + """ + collections: + puppies: + output: true + + collections_dir: collections + """ + When I run jekyll build + Then I should get a zero exit status + And the _site directory should exist + And the "_site/puppies/rover.html" file should exist + And I should see "excerpt for all docs." in "_site/puppies/rover.html" + And I should see "Random Content." in "_site/2009/03/27/gathered-post.html" diff --git a/lib/jekyll/tags/include.rb b/lib/jekyll/tags/include.rb index 5836c4ac..0ee983dc 100644 --- a/lib/jekyll/tags/include.rb +++ b/lib/jekyll/tags/include.rb @@ -216,8 +216,15 @@ MSG if context.registers[:page].nil? context.registers[:site].source else - current_doc_dir = File.dirname(context.registers[:page]["path"]) - context.registers[:site].in_source_dir current_doc_dir + site = context.registers[:site] + page_payload = context.registers[:page] + resource_path = \ + if page_payload["collection"].nil? + page_payload["path"] + else + File.join(site.config["collections_dir"], page_payload["path"]) + end + site.in_source_dir File.dirname(resource_path) end end end