Merge pull request #2295 from jekyll/add-documents-listing
This commit is contained in:
commit
c8a715d09b
|
@ -70,3 +70,15 @@ Feature: Collections
|
||||||
When I run jekyll build
|
When I run jekyll build
|
||||||
Then the _site directory should exist
|
Then the _site directory should exist
|
||||||
And I should see "Collections: _methods/configuration.md _methods/sanitized_path.md _methods/site/generate.md _methods/site/initialize.md _methods/um_hi.md" in "_site/index.html"
|
And I should see "Collections: _methods/configuration.md _methods/sanitized_path.md _methods/site/generate.md _methods/site/initialize.md _methods/um_hi.md" in "_site/index.html"
|
||||||
|
|
||||||
|
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
|
||||||
|
And I have a "_config.yml" file with content:
|
||||||
|
"""
|
||||||
|
collections:
|
||||||
|
- methods
|
||||||
|
"""
|
||||||
|
When I run jekyll build
|
||||||
|
Then the _site directory should exist
|
||||||
|
And I should see "All documents: _methods/configuration.md _methods/sanitized_path.md _methods/site/generate.md _methods/site/initialize.md _methods/um_hi.md" in "_site/index.html"
|
||||||
|
|
|
@ -228,5 +228,14 @@ module Jekyll
|
||||||
path <=> anotherDocument.path
|
path <=> anotherDocument.path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Determine whether this document should be written.
|
||||||
|
# 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.
|
||||||
|
def write?
|
||||||
|
collection && collection.write?
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -325,6 +325,7 @@ module Jekyll
|
||||||
"categories" => post_attr_hash('categories'),
|
"categories" => post_attr_hash('categories'),
|
||||||
"tags" => post_attr_hash('tags'),
|
"tags" => post_attr_hash('tags'),
|
||||||
"collections" => collections,
|
"collections" => collections,
|
||||||
|
"documents" => documents,
|
||||||
"data" => site_data
|
"data" => site_data
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
@ -405,18 +406,18 @@ module Jekyll
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def docs_to_write
|
||||||
|
documents.select(&:write?)
|
||||||
|
end
|
||||||
|
|
||||||
def documents
|
def documents
|
||||||
collections.reduce(Set.new) do |docs, (_, collection)|
|
collections.reduce(Set.new) do |docs, (_, collection)|
|
||||||
if collection.write?
|
|
||||||
docs.merge(collection.docs)
|
docs.merge(collection.docs)
|
||||||
else
|
end.to_a
|
||||||
docs
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_site_file
|
def each_site_file
|
||||||
%w(posts pages static_files documents).each do |type|
|
%w(posts pages static_files docs_to_write).each do |type|
|
||||||
send(type).each do |item|
|
send(type).each do |item|
|
||||||
yield item
|
yield item
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue