Class: JekyllGetAPI::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-get-api/collection.rb

Class Method Summary collapse

Class Method Details

.generate(site, resource, json) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/jekyll-get-api/collection.rb', line 3

def self.generate(site, resource, json)
  collection = site.collections[resource['name']]
  data_key = resource['data_key'] || 'data'
  id = resource['document_id'] || 'id'

  json[data_key].each do |item|
    document = Jekyll::Document.new(
      "#{item[id]}.md",
      { site: site, collection: collection }
    )
    document.data.merge!(item)
    collection.docs << document
  end
end