jekyll-airtable 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.env.example +4 -0
- data/.gitignore +2 -1
- data/Gemfile.lock +1 -1
- data/README.md +77 -12
- data/lib/jekyll-airtable/api.rb +2 -1
- data/lib/jekyll-airtable/client.rb +29 -16
- data/lib/jekyll-airtable/version.rb +1 -1
- data/lib/jekyll/airtable_fetcher.rb +13 -10
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 395f32572de790075218a8054c2f2d85edfb7d26
|
4
|
+
data.tar.gz: f991aff018e93d7c909fbfc8afb22555a41f4604
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bec4a8ec0e745078d43279e4faa5a0e919a4d3394ac1a8575337dc7c0465868d8786550d5ec059d05a58e082edeea28b2b041b552a0dc805479da6deb7a74393
|
7
|
+
data.tar.gz: 3ad0bc15fb63dbf0fc34b7837d50da2e6f8a797b470be20099bd1577cbc380c4c8655b0870d2ed3e52f9a6ac302dc1e3f8d422d0bf73a0208bca7704cbd0572a
|
data/.env.example
ADDED
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@ This gem enables you to easily integrate Airtable with Jekyll site and use it as
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
Add this line to your
|
7
|
+
Add this line to your Jekyll site Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
10
|
gem 'jekyll-airtable'
|
@@ -12,28 +12,93 @@ gem 'jekyll-airtable'
|
|
12
12
|
|
13
13
|
And then execute:
|
14
14
|
|
15
|
-
$ bundle
|
15
|
+
$ bundle install
|
16
16
|
|
17
|
-
|
17
|
+
## Usage
|
18
18
|
|
19
|
-
|
19
|
+
1. Because you will have to mention/use your API key, it is VERY RECOMMENDED to use dotenv so you do not have your API key lying around in plain sight.
|
20
|
+
```ruby
|
21
|
+
gem 'dotenv'
|
22
|
+
```
|
23
|
+
run bundle install again
|
20
24
|
|
21
|
-
|
25
|
+
2. Add this to your repo .gitignore (create one if does not exist):
|
26
|
+
```
|
27
|
+
.env
|
28
|
+
```
|
29
|
+
|
30
|
+
3. Copy the .env.example in this repo to the root of your project, rename it to .env then fill it for your needs.
|
31
|
+
4. Set the SYNC_WITH_AIRTABLE key in the .env to 'true'
|
32
|
+
|
33
|
+
```
|
34
|
+
SYNC_WITH_AIRTABLE='true'
|
35
|
+
```
|
36
|
+
|
37
|
+
5. You need to add a custom plugin to get the dotenv to work, you do this by creating a folder ```_plugins``` (if does not exist already) inside your Jekyll repo
|
38
|
+
6. Inside the ```/_plugins ```, create a file called "environment_variables_generator.rb", with this as the content:
|
22
39
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
40
|
+
```ruby
|
41
|
+
# Plugin to add environment variables to the `site` object in Liquid templates
|
42
|
+
require 'dotenv'
|
43
|
+
|
44
|
+
module Jekyll
|
45
|
+
class EnvironmentVariablesGenerator < Generator
|
46
|
+
priority :highest
|
47
|
+
|
48
|
+
def generate(site)
|
49
|
+
Dotenv.overload
|
50
|
+
site.config['env'] = Dotenv.overload
|
51
|
+
|
52
|
+
site.config['SYNC_WITH_AIRTABLE'] = ENV['SYNC_WITH_AIRTABLE']
|
53
|
+
site.config['AIRTABLE_API_KEY'] = ENV['AIRTABLE_API_KEY']
|
54
|
+
site.config['AIRTABLE_BASE_UID'] = ENV['AIRTABLE_BASE_UID']
|
55
|
+
site.config['AIRTABLE_TABLE_NAMES'] = ENV['AIRTABLE_TABLE_NAMES'].split(',').map(&:strip)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
Now the secret keys can be accessed by Jekyll without being visible to the public.
|
62
|
+
|
63
|
+
7. Now, you need to declare the plugins in the config.yml
|
64
|
+
```yml
|
65
|
+
plugins:
|
66
|
+
- jekyll-airtable
|
67
|
+
- environment_variables_generator
|
68
|
+
```
|
69
|
+
|
70
|
+
8. Finally, you can execute the plugin using ```sh bundle exec jekyll serve ``` or ```sh bundle exec jekyll build ```
|
71
|
+
|
72
|
+
For production, you also have to set those keys and values.
|
73
|
+
|
74
|
+
9. You then need to set the collections on the ```_config.yml ``` so that Jekyll recognizes them. The snippets below here are taken from https://github.com/galliani/airbase/blob/master/_config.yml. The collections on that repo are "use_cases", "whitepapers", and "tutorials", taken from the Airtable of "Use Cases", "Whitepapers", and "Tutorials" respectively.
|
75
|
+
|
76
|
+
```yml
|
77
|
+
collections_dir: collections
|
78
|
+
collections:
|
79
|
+
use_cases:
|
80
|
+
output: true
|
81
|
+
whitepapers:
|
82
|
+
output: true
|
83
|
+
tutorials:
|
84
|
+
output: true
|
85
|
+
|
86
|
+
defaults:
|
87
|
+
- scope:
|
88
|
+
type: "whitepapers"
|
89
|
+
values:
|
90
|
+
layout: "page" # any jekyll layout file you already have in the _layouts that you want to use for this collection type.
|
91
|
+
```
|
27
92
|
|
28
93
|
## Development
|
29
94
|
|
30
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
95
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
31
96
|
|
32
97
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
33
98
|
|
34
99
|
## Contributing
|
35
100
|
|
36
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
101
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/galliani/jekyll-airtable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
37
102
|
|
38
103
|
## License
|
39
104
|
|
@@ -41,4 +106,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
41
106
|
|
42
107
|
## Code of Conduct
|
43
108
|
|
44
|
-
Everyone interacting in the Jekyll::Airtable project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
109
|
+
Everyone interacting in the Jekyll::Airtable project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/galliani/jekyll-airtable/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/jekyll-airtable/api.rb
CHANGED
@@ -15,30 +15,43 @@ module Jekyll
|
|
15
15
|
|
16
16
|
@connection.authorization(:Bearer, Airtable.api_key)
|
17
17
|
|
18
|
+
records = []
|
19
|
+
offset = nil
|
20
|
+
counter = 1
|
21
|
+
|
22
|
+
begin
|
23
|
+
looper = "request no. #{counter}"
|
24
|
+
puts 'Sending ' + looper
|
25
|
+
|
26
|
+
params[:offset] = offset if !offset.nil?
|
27
|
+
|
28
|
+
data = send_get_request(table_name, params)
|
29
|
+
puts "Response received for the " + looper
|
30
|
+
|
31
|
+
records << data['records']
|
32
|
+
offset = data['offset']
|
33
|
+
|
34
|
+
# Pause for 1 second, just to be safe
|
35
|
+
sleep 1
|
36
|
+
counter += 1
|
37
|
+
end while !offset.nil?
|
38
|
+
|
39
|
+
records.flatten
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def send_get_request(table_name, params)
|
18
45
|
response = @connection.get do |req|
|
19
46
|
req.url URI.escape(table_name)
|
20
47
|
|
21
|
-
default_params = params
|
48
|
+
default_params = params
|
22
49
|
default_params.keys.each do |key|
|
23
50
|
processing_query_params(req, default_params, key)
|
24
51
|
end
|
25
52
|
end
|
26
53
|
|
27
|
-
response.body
|
28
|
-
end
|
29
|
-
|
30
|
-
def retrieve_record(table_name:, record_uid:)
|
31
|
-
@connection = Faraday.new(url: versioned_base_endpoint_url) do |faraday|
|
32
|
-
faraday.response :logger # log requests to STDOUT
|
33
|
-
faraday.request :url_encoded
|
34
|
-
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
35
|
-
end
|
36
|
-
|
37
|
-
@connection.authorization(:Bearer, Airtable.api_key)
|
38
|
-
|
39
|
-
response = @connection.get(URI.escape(table_name) + '/' + record_uid)
|
40
|
-
|
41
|
-
response.body
|
54
|
+
JSON.parse(response.body)
|
42
55
|
end
|
43
56
|
|
44
57
|
end
|
@@ -18,24 +18,27 @@ module Jekyll
|
|
18
18
|
client = Airtable.client(base_uid: site.config['AIRTABLE_BASE_UID'])
|
19
19
|
|
20
20
|
site.config['AIRTABLE_TABLE_NAMES'].each do |table_name|
|
21
|
-
records =
|
21
|
+
records = client.list_records(table_name: table_name)
|
22
22
|
next if records.size == 0
|
23
23
|
|
24
|
-
records_as_json = records['records']
|
25
24
|
converted_table_name = to_snake(table_name)
|
26
25
|
directory_name = "collections/_" + converted_table_name
|
27
26
|
|
28
27
|
Dir.mkdir(directory_name) unless File.exists?(directory_name)
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
records.each do |record|
|
30
|
+
fields = record['fields']
|
31
|
+
# We use the first field as the primary key
|
32
|
+
# Then find the value of the primary key to be stored as the slug, which
|
33
|
+
# will be used as file name and the path to the record in the url.
|
34
|
+
# However, if the record has field called 'slug', it will be used instead
|
35
|
+
pkey = fields.keys.first
|
36
|
+
slug = fields['slug'].nil? ? fields[pkey] : fields['slug']
|
37
|
+
uid = record['id']
|
38
|
+
|
39
|
+
out_file = File.new("#{directory_name}/#{slug}.md", "w")
|
33
40
|
out_file.puts(front_matter_mark)
|
34
|
-
|
35
|
-
# Store the uid
|
36
|
-
out_file.puts("uid: #{slug}")
|
37
|
-
|
38
|
-
fields = record_hash['fields']
|
41
|
+
out_file.puts("uid: #{uid}")
|
39
42
|
|
40
43
|
fields.each do |key, value|
|
41
44
|
snake_key = to_snake(key)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-airtable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Galih Muhammad
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -129,6 +129,7 @@ executables: []
|
|
129
129
|
extensions: []
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
|
+
- ".env.example"
|
132
133
|
- ".gitignore"
|
133
134
|
- ".rspec"
|
134
135
|
- ".travis.yml"
|