Generate items from `site.include` list only once (#8463)

Merge pull request 8463
This commit is contained in:
Ashwin Maroli 2020-11-09 17:33:16 +05:30 committed by GitHub
parent ddae19bbb4
commit db9ca22c24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 6 deletions

View File

@ -143,6 +143,40 @@ Feature: Site configuration
But the "_site/about.html" file should exist
And I should see "John Doe" in "_site/about.html"
Scenario: Process included files only once
Given I have a ".foobar" page that contains "dotfile with front matter"
And I have an ".htaccess" file that contains "SomeDirective"
And I have a "_redirects" file that contains "/foo/* /bar/* 301!"
And I have an "index.md" file with content:
"""
---
---
Dotpages: {{ site.pages | where: 'path', '.foobar' | size }}
Dotstatics: {{ site.static_files | where: 'path', '/_redirects' | size }}
"""
And I have a configuration file with "title" set to "Hello World"
When I run jekyll build
Then I should get a zero exit status
And the _site directory should exist
But the "_site/.foobar" file should not exist
And the "_site/_redirects" file should not exist
And I should see "Dotpages: 0" in "_site/index.html"
And I should see "Dotstatics: 0" in "_site/index.html"
When I have a configuration file with:
| key | value |
| title | Hello World |
| include | [.foobar, _redirects] |
When I run jekyll build
Then I should get a zero exit status
And I should not see "Conflict:" in the build output
And the _site directory should exist
And the "_site/.foobar" file should exist
And the "_site/_redirects" file should exist
And I should see "Dotpages: 1" in "_site/index.html"
And I should see "Dotstatics: 1" in "_site/index.html"
Scenario: Use Kramdown for markup
Given I have an "index.markdown" page that contains "[Google](https://www.google.com)"
And I have a configuration file with "markdown" set to "kramdown"

View File

@ -164,8 +164,6 @@ module Jekyll
entry_filter = EntryFilter.new(site)
site.include.each do |entry|
next if entry == ".htaccess"
entry_path = site.in_source_dir(entry)
next if File.directory?(entry_path)
next if entry_filter.symlink?(entry_path)
@ -175,13 +173,20 @@ module Jekyll
end
def read_included_file(entry_path)
dir = File.dirname(entry_path).sub(site.source, "")
file = Array(File.basename(entry_path))
if Utils.has_yaml_header?(entry_path)
site.pages.concat(PageReader.new(site, dir).read(file))
conditionally_generate_entry(entry_path, site.pages, PageReader)
else
site.static_files.concat(StaticFileReader.new(site, dir).read(file))
conditionally_generate_entry(entry_path, site.static_files, StaticFileReader)
end
end
def conditionally_generate_entry(entry_path, container, reader)
return if container.find { |item| site.in_source_dir(item.relative_path) == entry_path }
dir, files = File.split(entry_path)
dir.sub!(site.source, "")
files = Array(files)
container.concat(reader.new(site, dir).read(files))
end
end
end