jekyll-airtable-import 0.1.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 +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +108 -0
- data/lib/jekyll-airtable-import.rb +80 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9505b58d83a93712ea299e2229c7029cf01fae5016067ea0be813e22d360e436
|
4
|
+
data.tar.gz: 1aa60367ee33d8c53bdbb4cf1023a315ec07a1b98fa0fd3b95428666d71a1bb4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '070952fd2c85015fc5900fb36c72d40dbbeeb4a6857ece1439bd55929f4749eba6886496eff59c152f1d09fec4760110057bcadf966a42a7519e687ddda68a30'
|
7
|
+
data.tar.gz: 288d0adde99cb70f6de980f76b9419e6ba1b0a1125c20afab87e04ffc32cbde59b45b26b61ecc342c241c454720d6013ddc11a18669fa3e7661ae6bcf5eba330
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 joe-irving
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# Jekyll Airtable importer
|
2
|
+
|
3
|
+
A simple plugin that used the [Airtable gem](https://rubygems.org/gems/airtable)
|
4
|
+
create data or collections in Jekyll.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add `gem "jekyll-airtable-import"` to your Jekyll sites Gemfile, under the
|
9
|
+
plugins group like so:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
# If you have any plugins, put them here!
|
13
|
+
group :jekyll_plugins do
|
14
|
+
gem "jekyll-airtable-import"
|
15
|
+
end
|
16
|
+
```
|
17
|
+
|
18
|
+
## Configuration
|
19
|
+
|
20
|
+
To configure your Jekyll site to import from Airtable:
|
21
|
+
|
22
|
+
### 1. Add the API key to your environment
|
23
|
+
|
24
|
+
Add an environment variable called `AIRTABLE_API_KEY` to all the environments that
|
25
|
+
your site will be built in.
|
26
|
+
|
27
|
+
### 2. Edit your `_config.yml` file
|
28
|
+
|
29
|
+
To tell your Jekyll site which tables to import your site from by defining them
|
30
|
+
in the `airtable` as a list of tables:
|
31
|
+
|
32
|
+
```yaml
|
33
|
+
airtable:
|
34
|
+
faqs: # This key defines the name of the data, in this case it would be available under site.data.faqs
|
35
|
+
app: app4ghFya5hfwmfVQ # the base ID for the Airtable
|
36
|
+
table: tbl4ghFya5hfwmfVQ # the table that contains your data (in this case faq). Can also be the table name
|
37
|
+
view: viw4ghFya5hfwmfVQ # the view that you would like to import. NB this will include hidden fields in the view, but only include records in that view.
|
38
|
+
resources:
|
39
|
+
app:
|
40
|
+
table:
|
41
|
+
view:
|
42
|
+
combine: true # Combine any existing collections with this data? Defaults to false
|
43
|
+
partners:
|
44
|
+
app:
|
45
|
+
table:
|
46
|
+
view:
|
47
|
+
fields: # A list of field names that would like to INCLUDE. Important as views do not filter out hidden fields
|
48
|
+
- Title
|
49
|
+
- URL
|
50
|
+
- Image
|
51
|
+
- Summary
|
52
|
+
# In the below case, "trainings" are a collection - so they can be output as pages etc.
|
53
|
+
# To define any of the imports as collections, just add a collection hash
|
54
|
+
trainings:
|
55
|
+
app:
|
56
|
+
table:
|
57
|
+
view:
|
58
|
+
fields:
|
59
|
+
- Content
|
60
|
+
- Title
|
61
|
+
- Summary
|
62
|
+
- Image
|
63
|
+
- Booking link
|
64
|
+
- Start Date
|
65
|
+
- End date
|
66
|
+
collection:
|
67
|
+
slug: title # the field title that should be used as the slug. NB the field titles are slugified. E.g. "Start Time" would end up as start_time
|
68
|
+
layout: event # the name of a layout that exists in your site's (or your site's theme) _layouts folder
|
69
|
+
content: content # the field title that should be used as the conent. NB the field titles are slugified. E.g. "Event Description" would end up as event_description
|
70
|
+
```
|
71
|
+
|
72
|
+
#### Import Fields
|
73
|
+
|
74
|
+
Each import's key defines its key in the sites data or collection. Each item in the list of imports has these fields:
|
75
|
+
|
76
|
+
| Field | Required? | Notes |
|
77
|
+
| ----: | :-------: |---|
|
78
|
+
| app | :heavy_check_mark: | The base ID for the Airtable. Starts with `app` and can be found in an Airtable URL |
|
79
|
+
| table | :heavy_check_mark: | The table ID or name for the collection/data/ Starts with `tbl` and can be found in an Airtable URL |
|
80
|
+
| view | | The view ID (or name) for the collection/data/ Starts with `viw` and can be found in an Airtable URL |
|
81
|
+
| fields | | A list of fields found in the headings of Airtable columns, defining the only fields to be imported |
|
82
|
+
| collection | | If this is defined, the Airtable table will be imported into a collection rather than data. |
|
83
|
+
| combine | | Define this as truthy for any existing collections to be combined with the imported data. Already is done automatically for data and data, or collections and collections. |
|
84
|
+
|
85
|
+
|
86
|
+
#### Collection feilds
|
87
|
+
|
88
|
+
| Field | Required? | Notes |
|
89
|
+
| ----: | :---------: |---|
|
90
|
+
| slug | :heavy_check_mark: | the field title that should be used as the slug. NB the field titles are slugified. E.g. "Start Time" would end up as start_time |
|
91
|
+
| layout | :heavy_check_mark: | the name of a layout that exists in your site's (or your site's theme) _layouts folder |
|
92
|
+
| content | :heavy_check_mark: | the field title that should be used as the conent. NB the field titles are slugified. E.g. "Event Description" would end up as event_description |
|
93
|
+
|
94
|
+
## Example
|
95
|
+
|
96
|
+
Check out an example here
|
97
|
+
|
98
|
+
## Collaborations
|
99
|
+
|
100
|
+
Fork away :)
|
101
|
+
|
102
|
+
## Licence
|
103
|
+
|
104
|
+
MIT
|
105
|
+
|
106
|
+
## Issues
|
107
|
+
|
108
|
+
Just create a new issue
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'jekyll'
|
2
|
+
require 'airtable'
|
3
|
+
require 'active_support/all'
|
4
|
+
|
5
|
+
module Airtable
|
6
|
+
# Generates Jekyll Collections and Data from Airtable bases.
|
7
|
+
#
|
8
|
+
# See https://tippingpointuk.github.io/jekyll-airtable-import for more.
|
9
|
+
class Generator < ::Jekyll::Generator
|
10
|
+
priority :medium
|
11
|
+
|
12
|
+
def parse_data(data)
|
13
|
+
data_parse = []
|
14
|
+
data.each do |item|
|
15
|
+
# Extract attachments to just their URL
|
16
|
+
item.each do |key,val|
|
17
|
+
if val.kind_of?(Array)
|
18
|
+
if val[0]['url']
|
19
|
+
item[key] = val[0]['url']
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
data_parse.push(item)
|
24
|
+
end
|
25
|
+
data_parse
|
26
|
+
end
|
27
|
+
def generate(site)
|
28
|
+
return unless site.config['airtable']
|
29
|
+
# Get API key from environment
|
30
|
+
if ENV['AIRTABLE_API_KEY']
|
31
|
+
api_key = ENV['AIRTABLE_API_KEY']
|
32
|
+
else
|
33
|
+
warn "No airtable api key found. Make sure your key is available as AIRTABLE_API_KEY in the local environment."
|
34
|
+
end
|
35
|
+
# Pass in api key to client
|
36
|
+
@client = Airtable::Client.new(api_key)
|
37
|
+
site.config['airtable'].each do |name, conf|
|
38
|
+
# Pass in the app key and table name
|
39
|
+
@table = @client.table(conf['app'], conf['table'])
|
40
|
+
# Get records where the Published field is checked
|
41
|
+
@records = @table.all(:view => conf['view'],:fields => conf['fields'])
|
42
|
+
# Extract data to a hash
|
43
|
+
data = @records.map { |record| record.attributes }
|
44
|
+
parsed_data = parse_data(data)
|
45
|
+
if conf['collection']
|
46
|
+
slug_field = conf['collection']['slug']
|
47
|
+
layout = conf['collection']['layout']
|
48
|
+
if site.collections[name]
|
49
|
+
new_collection = site.collections[name]
|
50
|
+
else
|
51
|
+
new_collection = Jekyll::Collection.new(site, name)
|
52
|
+
end
|
53
|
+
# new_collection = Jekyll::Collection.new(site, name)
|
54
|
+
parsed_data.each do |item|
|
55
|
+
if item[slug_field] and item[slug_field] != ''
|
56
|
+
content = item[conf['collection']['content']]
|
57
|
+
#puts content
|
58
|
+
slug = Jekyll::Utils.slugify(item[slug_field])
|
59
|
+
path = File.join(site.source, "_#{name}", "#{slug}.md")
|
60
|
+
doc = Jekyll::Document.new(path, collection: new_collection, site: site)
|
61
|
+
item.merge!({ 'layout' => layout, 'slug' => slug })
|
62
|
+
doc.merge_data!(item.except('id'))
|
63
|
+
|
64
|
+
doc.content = content
|
65
|
+
new_collection.docs << doc
|
66
|
+
end
|
67
|
+
end
|
68
|
+
site.collections[name] = new_collection
|
69
|
+
else
|
70
|
+
site.data[name] = data
|
71
|
+
if conf['combine'] and site.collections.key?(name)
|
72
|
+
site.collections[name].docs.each do |document|
|
73
|
+
site.data[name].append(document)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-airtable-import
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- joe-irving
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-10-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.7'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.7'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: airtable
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.0.9
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.0.9
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: activesupport
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '6.1'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '6.1'
|
61
|
+
description:
|
62
|
+
email:
|
63
|
+
- joe@irving.me.uk
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- lib/jekyll-airtable-import.rb
|
72
|
+
homepage: https://tippingpointuk.github.io/jekyll-airtable-import
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 2.5.0
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubygems_version: 3.1.2
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: A simple importer from airtable, to collections or data
|
95
|
+
test_files: []
|