├── .gitignore ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── bin ├── console └── setup ├── jekyll-airtable_data.gemspec ├── lib └── jekyll │ ├── airtable_data.rb │ └── airtable_data │ └── version.rb └── spec ├── jekyll └── airtable_data_spec.rb └── spec_helper.rb /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | Gemfile.lock 3 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | gemspec 3 | 4 | gem 'airtable' 5 | gem 'bigdecimal' 6 | gem 'activesupport' 7 | gem 'json' 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Dan Klammer 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Jekyll Airtable Data 2 | 3 | Jekyll plugin to pull down your Airtable tables as datafiles (JSON) through Jekyll Commands. 4 | 5 | ## Installation 6 | 7 | Add plugin to your Gemfile: 8 | 9 | ```ruby 10 | gem 'jekyll-airtable_data' 11 | ``` 12 | 13 | Add Airtable settings to your _config.yml file: 14 | 15 | ```yml 16 | airtable_data: 17 | api_key: [Your Airtable API Key] # Airtable API key available in the API documentation for your base 18 | app_id: [Your Airtable App ID] # Airtable app ID found in the API documentation for your base 19 | tables: 20 | - [Your Airtable Table Name 1] 21 | - [Your Airtable Table Name 2] 22 | - [Your Airtable Table Name 3] 23 | ``` 24 | 25 | ## Run Airtable Data 26 | 27 | Execute via Jekyll Command as needed (and works great with Netlify's Build command): 28 | 29 | $ bundle exec jekyll airtable_data 30 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | require "rspec/core/rake_task" 3 | 4 | RSpec::Core::RakeTask.new(:spec) 5 | 6 | task :default => :spec 7 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "bundler/setup" 4 | require "jekyll/airtable_data" 5 | 6 | # You can add fixtures and/or initialization code here to make experimenting 7 | # with your gem easier. You can also use a different console, if you like. 8 | 9 | # (If you use this, don't forget to add pry to your Gemfile!) 10 | # require "pry" 11 | # Pry.start 12 | 13 | require "irb" 14 | IRB.start(__FILE__) 15 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /jekyll-airtable_data.gemspec: -------------------------------------------------------------------------------- 1 | 2 | lib = File.expand_path("../lib", __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require "jekyll/airtable_data/version" 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "jekyll-airtable_data" 8 | spec.version = Jekyll::AirtableData::VERSION 9 | spec.date = "2018-10-29" 10 | spec.summary = "Airtable Data" 11 | spec.description = "Jekyll plugin to pull down your Airtable tables as Datafiles (JSON) through Jekyll Commands" 12 | spec.authors = ["Dan Klammer"] 13 | spec.homepage = "https://github.com/danklammer/jekyll-airtable_data" 14 | spec.license = "MIT" 15 | 16 | # Specify which files should be added to the gem when it is released. 17 | # The `git ls-files -z` loads the files in the RubyGem that have been added into git. 18 | spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do 19 | `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 20 | end 21 | spec.bindir = "exe" 22 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 23 | spec.require_paths = ["lib"] 24 | 25 | spec.add_dependency "jekyll", "~> 3.8" 26 | spec.add_dependency "airtable" 27 | spec.add_dependency "bigdecimal" 28 | spec.add_dependency "activesupport" 29 | spec.add_dependency "json" 30 | 31 | spec.add_development_dependency "bundler", ">= 2.2.10" 32 | spec.add_development_dependency "rake", ">= 12.3.3" 33 | spec.add_development_dependency "rspec", "~> 3.0" 34 | 35 | end 36 | -------------------------------------------------------------------------------- /lib/jekyll/airtable_data.rb: -------------------------------------------------------------------------------- 1 | require "jekyll/airtable_data/version" 2 | require 'json' 3 | require 'airtable' 4 | require 'active_support/all' 5 | 6 | module Jekyll 7 | module Commands 8 | class AirtableData < Command 9 | class << self 10 | def init_with_program(prog) 11 | prog.command(:airtable_data) do |c| 12 | c.action do |args, options| 13 | 14 | @airtable_config = Jekyll.configuration({})['airtable_data'] 15 | @api_key = @airtable_config['api_key'] 16 | @app_id = @airtable_config['app_id'] 17 | 18 | @client = Airtable::Client.new("#{@api_key}") 19 | 20 | @airtable_config['tables'].each do |table| 21 | 22 | @table = @client.table("#{@app_id}", "#{table}") 23 | @records = @table.all(:sort => ["Name", :asc]) 24 | 25 | dirname = File.dirname("_data/#{table}") 26 | unless File.directory?(dirname) 27 | FileUtils.mkdir_p(dirname) 28 | end 29 | 30 | File.open(dirname + "/" + table.parameterize + ".json", "w") do |f| 31 | data = @records.map { |record| record.attributes } 32 | f.write(data.to_json) 33 | end 34 | 35 | Jekyll.logger.info "Airable:","Generated _data/#{table.parameterize}.json" 36 | 37 | end 38 | 39 | Jekyll.logger.info "Airtable: Sync Complete!" 40 | 41 | end 42 | end 43 | end 44 | end 45 | end 46 | end 47 | end -------------------------------------------------------------------------------- /lib/jekyll/airtable_data/version.rb: -------------------------------------------------------------------------------- 1 | module Jekyll 2 | module AirtableData 3 | VERSION = "1.0.0" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /spec/jekyll/airtable_data_spec.rb: -------------------------------------------------------------------------------- 1 | RSpec.describe Jekyll::AirtableData do 2 | it "has a version number" do 3 | expect(Jekyll::AirtableData::VERSION).not_to be nil 4 | end 5 | 6 | it "does something useful" do 7 | expect(false).to eq(true) 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require "bundler/setup" 2 | require "jekyll/airtable_data" 3 | 4 | RSpec.configure do |config| 5 | # Enable flags like --only-failures and --next-failure 6 | config.example_status_persistence_file_path = ".rspec_status" 7 | 8 | # Disable RSpec exposing methods globally on `Module` and `main` 9 | config.disable_monkey_patching! 10 | 11 | config.expect_with :rspec do |c| 12 | c.syntax = :expect 13 | end 14 | end 15 | --------------------------------------------------------------------------------