Skip to content

Commit

Permalink
Backport #8756 for v4.2.x: Respect collections_dir config within incl…
Browse files Browse the repository at this point in the history
…ude tag (#8794)

Respect collections_dir config within include tag
This backports aa9a416 and 1aea158 to 4.2-stable
  • Loading branch information
ashmaroli committed Sep 16, 2021
1 parent 3c9a7ee commit 55a39dd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
19 changes: 19 additions & 0 deletions features/incremental_rebuild.feature
Expand Up @@ -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"
Expand Down
15 changes: 10 additions & 5 deletions lib/jekyll/tags/include.rb
Expand Up @@ -234,12 +234,17 @@ def realpath_prefixed_with?(path, dir)
end

def add_include_to_dependency(inclusion, context)
return unless context.registers[:page]&.key?("path")
page = context.registers[:page]
return unless page&.key?("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(
@site.in_source_dir(context.registers[:page]["path"]),
inclusion.path
)
@site.regenerator.add_dependency(absolute_path, inclusion.path)
end
end

Expand Down

0 comments on commit 55a39dd

Please sign in to comment.