diff --git a/features/include_tag.feature b/features/include_tag.feature index c7e03dedbe3..427c1bb4f0c 100644 --- a/features/include_tag.feature +++ b/features/include_tag.feature @@ -77,3 +77,15 @@ Feature: Include tags When I run jekyll build Then the _site directory should exist And I should see "one included" in "_site/index.html" + + Scenario: Include a file and rebuild when include content is changed + Given I have an _includes directory + And I have an "_includes/one.html" file that contains "include" + And I have an "index.html" page that contains "{% include one.html %}" + When I run jekyll build + Then the _site directory should exist + And I should see "include" in "_site/index.html" + When I wait 1 second + Then I have an "_includes/one.html" file that contains "include content changed" + When I run jekyll build + Then I should see "include content changed" in "_site/index.html" diff --git a/lib/jekyll/tags/include.rb b/lib/jekyll/tags/include.rb index 92ce7c628e6..de9446a0600 100644 --- a/lib/jekyll/tags/include.rb +++ b/lib/jekyll/tags/include.rb @@ -123,7 +123,7 @@ def render(context) end begin - partial = site.liquid_renderer.file(path).parse(read_file(path, context)) + partial = load_cached_partial(path, context) context.stack do context['include'] = parse_params(context) if @params @@ -134,6 +134,19 @@ def render(context) end end + def load_cached_partial(path, context) + cached_partials = context.registers[:cached_partials] || {} + + if cached = cached_partials[path] + return cached + end + + partial = context.registers[:site].liquid_renderer.file(path).parse(read_file(path, context)) + cached_partials[path] = partial + context.registers[:cached_partials] = cached_partials + partial + end + def resolved_includes_dir(context) context.registers[:site].in_source_dir(@includes_dir) end