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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/jekyll-open-sdg-plugins/fetch_remote_data.rb', line 11
def generate(site)
if !site.config['jekyll_get_json']
if site.config['remote_data_prefix']
prefix = site.config['remote_data_prefix']
site.config['remotedatabaseurl'] = prefix
endpoints = {
'meta' => 'meta/all.json',
'headlines' => 'headline/all.json',
'schema' => 'meta/schema.json',
'reporting' => 'stats/reporting.json'
}
endpoints.each do |key, value|
target = site.data[key]
endpoint = prefix + '/' + value
begin
source = JSON.load(open(endpoint))
if target
target.deep_merge(source)
else
site.data[key] = source
end
rescue StandardError => e
puts e.message
abort 'Unable to fetch remote data from: ' + endpoint
end
end
end
if site.config['remote_translations']
key = 'translations'
target = site.data[key]
site.config['remote_translations'].each do |endpoint|
begin
source = JSON.load(open(endpoint))
if target
target.deep_merge(source)
else
site.data[key] = source
end
rescue StandardError => e
puts e.message
abort 'Unable to fetch remote translation from: ' + endpoint
end
end
end
end
end
|