Avoid caching resource when called via `include_relative` tag (#9784)
Merge pull request 9784
This commit is contained in:
		
							parent
							
								
									82efcc4c51
								
							
						
					
					
						commit
						07a01b0bc9
					
				|  | @ -58,3 +58,22 @@ Feature: include_relative Tag | |||
|     Then I should get a zero exit status | ||||
|     And the _site directory should exist | ||||
|     And I should see "Welcome back Dear Reader!" in "_site/index.html" | ||||
| 
 | ||||
|   Scenario: Include multiple files relative to a page at root | ||||
|     Given I have an "apple.md" page with foo "bar" that contains "{{ page.path }}, {{ page.foo }}" | ||||
|     And I have an "banana.md" page with content: | ||||
|       """ | ||||
|         {% include_relative apple.md %} | ||||
|         {% include_relative cherry.md %} | ||||
| 
 | ||||
|         {{ page.path }} | ||||
|       """ | ||||
|     And I have an "cherry.md" page with foo "lipsum" that contains "{{ page.path }}, {{ page.foo }}" | ||||
|     When I run jekyll build | ||||
|     Then I should get a zero exit status | ||||
|     And the _site directory should exist | ||||
|     And I should see "<p>apple.md, bar</p>" in "_site/apple.html" | ||||
|     And I should see "<hr />\n<p>foo: bar" in "_site/banana.html" | ||||
|     And I should see "<hr />\n<p>foo: lipsum" in "_site/banana.html" | ||||
|     And I should see "<p>cherry.md, lipsum</p>" in "_site/cherry.html" | ||||
|     But I should not see "foo: lipsum" in "_site/cherry.html" | ||||
|  |  | |||
|  | @ -249,6 +249,11 @@ module Jekyll | |||
|     end | ||||
| 
 | ||||
|     class IncludeRelativeTag < IncludeTag | ||||
|       def load_cached_partial(path, context) | ||||
|         context.registers[:cached_partials] ||= {} | ||||
|         context.registers[:cached_partials][path] ||= parse_partial(path, context) | ||||
|       end | ||||
| 
 | ||||
|       def tag_includes_dirs(context) | ||||
|         Array(page_path(context)).freeze | ||||
|       end | ||||
|  | @ -267,6 +272,17 @@ module Jekyll | |||
|         path = File.join(site.config["collections_dir"], path) if page["collection"] | ||||
|         path.delete_suffix("/#excerpt") | ||||
|       end | ||||
| 
 | ||||
|       # Since Jekyll 4 caches convertibles based on their path within the only instance of | ||||
|       # `LiquidRenderer`, initialize a new LiquidRenderer instance on every render of this | ||||
|       # tag to bypass caching rendered output of page / document. | ||||
|       def parse_partial(path, context) | ||||
|         LiquidRenderer.new(context.registers[:site]).file(path).parse(read_file(path, context)) | ||||
|       rescue Liquid::Error => e | ||||
|         e.template_name = path | ||||
|         e.markup_context = "included " if e.markup_context.nil? | ||||
|         raise e | ||||
|       end | ||||
|     end | ||||
|   end | ||||
| end | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue