Skip to content

Instantly share code, notes, and snippets.

@dhcole
Last active August 29, 2015 14:17
Show Gist options
  • Save dhcole/b813f0a1c4fc3290d31d to your computer and use it in GitHub Desktop.
Save dhcole/b813f0a1c4fc3290d31d to your computer and use it in GitHub Desktop.

Install

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

Configure

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

Example

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

Or

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:

{% for member in site.data.team %}
  Hello {{member[1].first_name}}
{% endfor %}
require 'open-uri'
module Jekyll_Get
class Generator < Jekyll::Generator
def generate(site)
config = site.config['jekyll_get']
if !config
return
end
if !config.kind_of?(Array)
config = [config]
end
config.each { |d| site.data[d['data']] = JSON.load(open(d['json'])) }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment