From aa9a4164d012956ccc4ec296ab3b3fccab3096db Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Thu, 5 Aug 2021 20:40:01 +0530 Subject: [PATCH] Respect collections_dir config within include tag (#8756) Merge pull request 8756 --- features/incremental_rebuild.feature | 19 +++++++++++++++++++ lib/jekyll/tags/include.rb | 16 +++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/features/incremental_rebuild.feature b/features/incremental_rebuild.feature index 2ced57a6..2d22d2e1 100644 --- a/features/incremental_rebuild.feature +++ b/features/incremental_rebuild.feature @@ -67,6 +67,25 @@ Feature: Incremental rebuild And the _site directory should exist And I should see "Basic Site with include tag: Regenerated by Jekyll" in "_site/index.html" + Scenario: Rebuild when a dependency of document in custom collection_dir is changed + Given I have a _includes directory + And I have a configuration file with "collections_dir" set to "collections" + And I have a collections/_posts directory + And I have the following post within the "collections" directory: + | title | date | layout | content | + | Wargames | 2009-03-27 | default | Basic Site with include tag: {% include about.html %} | + And I have an "_includes/about.html" file that contains "Generated by Jekyll" + When I run jekyll build -I + Then I should get a zero exit status + And the _site directory should exist + And I should see "Basic Site with include tag: Generated by Jekyll" in "_site/2009/03/27/wargames.html" + When I wait 1 second + Then I have an "_includes/about.html" file that contains "Regenerated by Jekyll" + When I run jekyll build -I + Then I should get a zero exit status + And the _site directory should exist + And I should see "Basic Site with include tag: Regenerated by Jekyll" in "_site/2009/03/27/wargames.html" + Scenario: A themed-site and incremental regeneration Given I have a configuration file with "theme" set to "test-theme" And I have an "index.md" page that contains "Themed site" diff --git a/lib/jekyll/tags/include.rb b/lib/jekyll/tags/include.rb index a3ea8ff6..6befb3d5 100644 --- a/lib/jekyll/tags/include.rb +++ b/lib/jekyll/tags/include.rb @@ -234,12 +234,18 @@ module Jekyll end def add_include_to_dependency(inclusion, context) - return unless context.registers[:page]&.key?("path") + page = context.registers[:page] + return unless page&.key?("path") - @site.regenerator.add_dependency( - @site.in_source_dir(context.registers[:page]["path"]), - inclusion.path - ) + page_path = context.registers[:page]["path"] + absolute_path = \ + if page["collection"] + @site.in_source_dir(@site.config["collections_dir"], page_path) + else + @site.in_source_dir(page_path) + end + + @site.regenerator.add_dependency(absolute_path, inclusion.path) end end