Include data in the array of collections
This commit is contained in:
parent
aa502348e5
commit
62551b5ff9
|
@ -84,6 +84,11 @@ module Jekyll
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# The list of collections and their corresponding Jekyll::Collection instances.
|
||||||
|
# If config['collections'] is set, a new instance is created for each item in the collection.
|
||||||
|
# If config['collections'] is not set, a new hash is returned.
|
||||||
|
#
|
||||||
|
# Returns a Hash containing collection name-to-instance pairs.
|
||||||
def collections
|
def collections
|
||||||
@collections ||= if config['collections']
|
@collections ||= if config['collections']
|
||||||
Hash[config['collections'].map { |coll| [coll, Jekyll::Collection.new(self, coll)] } ]
|
Hash[config['collections'].map { |coll| [coll, Jekyll::Collection.new(self, coll)] } ]
|
||||||
|
@ -92,8 +97,11 @@ module Jekyll
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# The list of collections to render.
|
||||||
|
#
|
||||||
|
# The array of collection labels to render.
|
||||||
def to_render
|
def to_render
|
||||||
config['render'] || Array.new
|
@to_render ||= (config['render'] || Array.new)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Read Site data from disk and load it into internal data structures.
|
# Read Site data from disk and load it into internal data structures.
|
||||||
|
@ -180,14 +188,15 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns nothing
|
# Returns nothing
|
||||||
def read_data(dir)
|
def read_data(dir)
|
||||||
base = File.join(source, dir)
|
unless dir.eql?("_data")
|
||||||
return unless File.directory?(base) && (!safe || !File.symlink?(base))
|
Jekyll.logger.warn "Error:", "Data source directories other than '_data' have been removed.\n" +
|
||||||
|
"Please move your YAML files to `_data` and remove the `data_source` key from your `_config.yml`."
|
||||||
|
end
|
||||||
|
|
||||||
entries = Dir.chdir(base) { Dir['*.{yaml,yml}'] }
|
collections['data'] = Jekyll::Collection.new(self, "data")
|
||||||
entries.delete_if { |e| File.directory?(File.join(base, e)) }
|
collections['data'].read
|
||||||
data_collection = Jekyll::Collection.new(self, "data")
|
|
||||||
data_collection.read
|
collections['data'].docs.each do |doc|
|
||||||
data_collection.docs.each do |doc|
|
|
||||||
key = sanitize_filename(doc.basename(".*"))
|
key = sanitize_filename(doc.basename(".*"))
|
||||||
self.data[key] = doc.data
|
self.data[key] = doc.data
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue