Skip to content

Commit

Permalink
Cache include file to save liquid parsing time.
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Nov 9, 2015
1 parent 1c515c9 commit 7b52ddb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
12 changes: 12 additions & 0 deletions features/include_tag.feature
Expand Up @@ -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"
15 changes: 14 additions & 1 deletion lib/jekyll/tags/include.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 7b52ddb

Please sign in to comment.