Skip to content
This repository has been archived by the owner on Dec 27, 2019. It is now read-only.

Load cached files rather than remote json #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions _plugins/jekyll_get.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,18 @@ def generate(site)
config = [config]
end
config.each do |d|
begin
target = site.data[d['data']]
data_source = (site.config['data_source'] || '_data')
path = "#{data_source}/#{d['data']}.json"
if d['cache'] && File.exists?(path)
source = JSON.load(File.open(path))
else
source = JSON.load(open(d['json']))
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
site.data[d['data']] = source
if d['cache']
open(path, 'wb') do |file|
file << JSON.generate(site.data[d['data']])
end
rescue
next
end
end
end
Expand Down