Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
source "https://rubygems.org"

gem "jekyll"
gem "html-proofer"
gem "html-proofer"
gem 'json'
gem 'hash-joiner'
gem 'open-uri-cached'
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ GEM
ethon (0.8.1)
ffi (>= 1.3.0)
ffi (1.9.10)
hash-joiner (0.0.7)
safe_yaml
html-proofer (2.6.4)
activesupport (~> 4.2)
addressable (~> 2.3)
Expand Down Expand Up @@ -47,6 +49,7 @@ GEM
minitest (5.8.4)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
open-uri-cached (0.0.5)
parallel (1.6.2)
rb-fsevent (0.9.7)
rb-inotify (0.9.7)
Expand All @@ -65,8 +68,11 @@ PLATFORMS
ruby

DEPENDENCIES
hash-joiner
html-proofer
jekyll
json
open-uri-cached

BUNDLED WITH
1.11.2
3 changes: 0 additions & 3 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ gatekeeper_host:
# Dataset schema
schema: default

# Dataset schema
schema: default

# Categories
category_list:
- Arts / Culture / History
Expand Down
Empty file added _data/cache
Empty file.
40 changes: 40 additions & 0 deletions _plugins/jekyll_get.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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 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.cache[d['data']])
end
end
rescue
next
end
end
end
end
end
72 changes: 72 additions & 0 deletions _plugins/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Install

Add this file to `_plugins` in the root of your Jekyll site.

Add dependencies these dependencie to your sites Gemfile

```
gem 'json'
gem 'hash-joiner'
gem 'open-uri-cached'
```

# Run
`bundle install`
`jekyll build`
`jekyll

# Configure

This plugin reads settings from the `_config.yml` file. Add settings as attributes or an array of attributes for multiple files.

## Example

```yml
jekyll_get:
data: team
json: 'https://18f.gsa.gov/hub/api/team/'
```

Or

```yml
jekyll_get:
- data: team
json: 'https://18f.gsa.gov/hub/api/team/'
- data: projects
json: 'https://18f.gsa.gov/hub/api/projects/'
```

Use in a liquid template as if it were a local data file:

```liquid
{% for member in site.data.team %}
Hello {{member[1].first_name}}
{% endfor %}
```

Optionally, set a cache attribute to save a local copy of the data in the `_data` directory:

```yml
jekyll_get:
- data: team
json: 'https://18f.gsa.gov/hub/api/team/'
cache: true
- data: projects
json: 'https://18f.gsa.gov/hub/api/projects/'
cache: true
- data: pif_team
json: 'https://18f.gsa.gov/hub/api/pif_team/'
cache: true
- data: pif_projects
json: 'https://18f.gsa.gov/hub/api/pif_projects/'
cache: true
```

## Public domain

This project is in the worldwide [public domain](LICENSE.md). As stated in [CONTRIBUTING](CONTRIBUTING.md):

> This project is in the public domain within the United States, and copyright and related rights in the work worldwide are waived through the [CC0 1.0 Universal public domain dedication](https://creativecommons.org/publicdomain/zero/1.0/).
>
> All contributions to this project will be released under the CC0 dedication. By submitting a pull request, you are agreeing to comply with this waiver of copyright interest.