Improve handling non-default collection documents rendering and writing (#6795)
Merge pull request 6795
This commit is contained in:
parent
7508da11c1
commit
f8a66ca76c
|
@ -348,6 +348,20 @@ you specified in your `_config.yml` (if present) and the following information:
|
|||
<code>{% raw %}{{ site.collections | where: "label", "myCollection" | first }}{% endraw %}</code></p>
|
||||
</div>
|
||||
|
||||
<div class="note info">
|
||||
<h5>Collections and Time</h5>
|
||||
<p>Except for documents in hard-coded default collection <code>posts</code>, all documents in collections
|
||||
you create, are accessible via Liquid irrespective of their assigned date, if any, and therefore renderable.
|
||||
</p>
|
||||
<p>However documents are attempted to be written to disk only if the concerned collection
|
||||
metadata has <code>output: true</code>. Additionally, future-dated documents are only written if
|
||||
<code>site.future</code> <em>is also true</em>.
|
||||
</p>
|
||||
<p>More fine-grained control over documents being written to disk can be exercised by setting
|
||||
<code>published: false</code> (<em><code>true</code> by default</em>) in the document's front matter.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
### Documents
|
||||
|
||||
|
|
|
@ -116,7 +116,31 @@ Feature: Collections
|
|||
And the _site directory should exist
|
||||
And the "_site/puppies/fido.html" file should exist
|
||||
|
||||
Scenario: Hidden collection with document with future date
|
||||
Scenario: Access rendered collection with future dated document via Liquid
|
||||
Given I have a _puppies directory
|
||||
And I have the following documents under the puppies collection:
|
||||
| title | date | content |
|
||||
| Rover | 2007-12-31 | content for Rover. |
|
||||
| Fido | 2120-12-31 | content for Fido. |
|
||||
And I have a "_config.yml" file with content:
|
||||
"""
|
||||
collections:
|
||||
puppies:
|
||||
output: true
|
||||
"""
|
||||
And I have a "index.html" page that contains "Newest puppy: {% assign puppy = site.puppies.last %}{{ puppy.title }}"
|
||||
When I run jekyll build
|
||||
Then I should get a zero exit status
|
||||
And the _site directory should exist
|
||||
And I should see "Newest puppy: Fido" in "_site/index.html"
|
||||
But the "_site/puppies/fido.html" file should not exist
|
||||
When I run jekyll build --future
|
||||
Then I should get a zero exit status
|
||||
And the _site directory should exist
|
||||
And I should see "Newest puppy: Fido" in "_site/index.html"
|
||||
And the "_site/puppies/fido.html" file should exist
|
||||
|
||||
Scenario: Unrendered collection with future dated document
|
||||
Given I have a _puppies directory
|
||||
And I have the following documents under the puppies collection:
|
||||
| title | date | content |
|
||||
|
@ -139,6 +163,30 @@ Feature: Collections
|
|||
And the _site directory should exist
|
||||
And the "_site/puppies/fido.html" file should not exist
|
||||
|
||||
Scenario: Access unrendered collection with future dated document via Liquid
|
||||
Given I have a _puppies directory
|
||||
And I have the following documents under the puppies collection:
|
||||
| title | date | content |
|
||||
| Rover | 2007-12-31 | content for Rover. |
|
||||
| Fido | 2120-12-31 | content for Fido. |
|
||||
And I have a "_config.yml" file with content:
|
||||
"""
|
||||
collections:
|
||||
puppies:
|
||||
output: false
|
||||
"""
|
||||
And I have a "index.html" page that contains "Newest puppy: {% assign puppy = site.puppies.last %}{{ puppy.title }}"
|
||||
When I run jekyll build
|
||||
Then I should get a zero exit status
|
||||
And the _site directory should exist
|
||||
And I should see "Newest puppy: Fido" in "_site/index.html"
|
||||
But the "_site/puppies/fido.html" file should not exist
|
||||
When I run jekyll build --future
|
||||
Then I should get a zero exit status
|
||||
And the _site directory should exist
|
||||
And I should see "Newest puppy: Fido" in "_site/index.html"
|
||||
And the "_site/puppies/fido.html" file should not exist
|
||||
|
||||
Scenario: All the documents
|
||||
Given I have an "index.html" page that contains "All documents: {% for doc in site.documents %}{{ doc.relative_path }} {% endfor %}"
|
||||
And I have fixture collections
|
||||
|
|
|
@ -210,12 +210,11 @@ module Jekyll
|
|||
private
|
||||
|
||||
def read_document(full_path)
|
||||
doc = Jekyll::Document.new(full_path, :site => site, :collection => self)
|
||||
docs << Document.new(full_path, :site => site, :collection => self).tap do |doc|
|
||||
doc.read
|
||||
if site.publisher.publish?(doc) || !write?
|
||||
docs << doc
|
||||
else
|
||||
Jekyll.logger.debug "Skipped Publishing:", doc.relative_path
|
||||
if !site.publisher.publish?(doc) && site.publisher.hidden_in_the_future?(doc)
|
||||
Jekyll.logger.debug "Skip Publishing:", "#{doc.relative_path} has a future date"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -311,9 +311,10 @@ module Jekyll
|
|||
# Based on the Collection to which it belongs.
|
||||
#
|
||||
# True if the document has a collection and if that collection's #write?
|
||||
# method returns true, otherwise false.
|
||||
# method returns true, and if the site's Publisher will publish the document.
|
||||
# False otherwise.
|
||||
def write?
|
||||
collection && collection.write?
|
||||
collection && collection.write? && site.publisher.publish?(self)
|
||||
end
|
||||
|
||||
# The Document excerpt_separator, from the YAML Front-Matter or site
|
||||
|
|
|
@ -449,14 +449,16 @@ class TestDocument < JekyllUnitTest
|
|||
refute_nil @files.find do |doc|
|
||||
doc.relative_path == "_slides/example-slide-4.html"
|
||||
end
|
||||
assert_exist dest_dir("slides/example-slide-4.html")
|
||||
end
|
||||
end
|
||||
|
||||
context "with output overrides" do
|
||||
should "be output according its front matter" do
|
||||
assert_nil(
|
||||
@files.find { |doc| doc.relative_path == "_slides/non-outputted-slide.html" }
|
||||
)
|
||||
assert @files.find do |doc|
|
||||
doc.relative_path == "_slides/non-outputted-slide.html"
|
||||
end
|
||||
refute_exist dest_dir("slides/non-outputted-slide.html")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue