forked from 18F/jekyll-get
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jekyll_get.rb
49 lines (44 loc) · 1.06 KB
/
jekyll_get.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'json'
require 'hash-joiner'
require 'open-uri'
module Jekyll_Get
class Generator < Jekyll::Generator
safe true
priority :highest
def generate(site)
config = site.config['jekyll_get']
if !config
return
end
if !config.kind_of?(Array)
config = [config]
end
config.each do |d|
begin
target = site.data[d['data']]
source = JSON.load(open(d['json']))
if d['meta']
meta = d['meta']
source['items'].each { |item|
item['meta'] = meta
}
end
if target
HashJoiner.deep_merge target, source
else
site.data[d['data']] = source
end
if d['cache']
data_source = (site.config['data_source'] || '_data')
path = "#{data_source}/#{d['data']}.json"
open(path, 'wb') do |file|
file << JSON.generate(site.data[d['data']])
end
end
rescue
next
end
end
end
end
end