jekyll-airtable 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/jekyll-airtable/version.rb +1 -1
- data/lib/jekyll/airtable_fetcher.rb +50 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5d3193ed1ef6eb2ff3a561eac88eda5304ee6de
|
4
|
+
data.tar.gz: aa1721c7f178f12ff151ced96e49a0bb29397161
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b0e29168c98a7b926b400f0e2ddf7cd7b21f9041961bfc8744aa037690292246bf75101d2f134da8570e2590d999275abcecf00f031620e9e47ecb4a7c9760e
|
7
|
+
data.tar.gz: 42f9c568fef5fafc2dfeff8ddbeb3a25754dce5473a985a4df509a04220156800ff2d2a7742be6d028511306137698b6e4655786643eee357d9e4b38d89b4aa1
|
data/Gemfile.lock
CHANGED
@@ -11,19 +11,21 @@ module Jekyll
|
|
11
11
|
return false if site.config['AIRTABLE_API_KEY'].nil? || site.config['AIRTABLE_API_KEY'] == ''
|
12
12
|
return false if site.config['SYNC_WITH_AIRTABLE'] == 'false'
|
13
13
|
|
14
|
+
setup_directories
|
15
|
+
# For storing hashes of attachments that will be saved to the data file
|
16
|
+
@attachments_hash = {}
|
17
|
+
|
14
18
|
Airtable.configure do |config|
|
15
19
|
config.api_key = site.config['AIRTABLE_API_KEY']
|
16
20
|
end
|
17
21
|
|
18
|
-
client = Airtable.client(base_uid: site.config['AIRTABLE_BASE_UID'])
|
22
|
+
client = Airtable.client(base_uid: site.config['AIRTABLE_BASE_UID'])
|
19
23
|
|
20
24
|
site.config['AIRTABLE_TABLE_NAMES'].each do |table_name|
|
21
25
|
records = client.list_records(table_name: table_name)
|
22
26
|
next if records.size == 0
|
23
27
|
|
24
|
-
|
25
|
-
directory_name = "collections/_" + converted_table_name
|
26
|
-
|
28
|
+
directory_name = "collections/_" + to_snake(table_name)
|
27
29
|
Dir.mkdir(directory_name) unless File.exists?(directory_name)
|
28
30
|
|
29
31
|
records.each do |record|
|
@@ -34,9 +36,10 @@ module Jekyll
|
|
34
36
|
# However, if the record has field called 'slug', it will be used instead
|
35
37
|
pkey = fields.keys.first
|
36
38
|
slug = fields['slug'].nil? ? fields[pkey] : fields['slug']
|
39
|
+
filename = to_snake(slug) + '.md'
|
37
40
|
uid = record['id']
|
38
41
|
|
39
|
-
out_file = File.new("#{directory_name}/#{
|
42
|
+
out_file = File.new("#{directory_name}/#{filename}", "w")
|
40
43
|
out_file.puts(front_matter_mark)
|
41
44
|
out_file.puts("uid: #{uid}")
|
42
45
|
|
@@ -48,6 +51,7 @@ module Jekyll
|
|
48
51
|
write_array_values(out_file, value)
|
49
52
|
else
|
50
53
|
value = stringify_value_if_necessary(value)
|
54
|
+
|
51
55
|
out_file.puts("#{snake_key}: #{value}")
|
52
56
|
end
|
53
57
|
end
|
@@ -57,6 +61,8 @@ module Jekyll
|
|
57
61
|
out_file.close
|
58
62
|
end
|
59
63
|
end
|
64
|
+
|
65
|
+
write_attachments_data_file
|
60
66
|
end
|
61
67
|
|
62
68
|
private
|
@@ -71,15 +77,49 @@ module Jekyll
|
|
71
77
|
|
72
78
|
def write_array_values(file, array)
|
73
79
|
array.each do |element|
|
74
|
-
|
75
|
-
|
76
|
-
|
80
|
+
if is_this_is_an_attachment?(element)
|
81
|
+
# Store only the uid of the attachment in the front matter
|
82
|
+
value = element['id']
|
83
|
+
|
84
|
+
# Store the hash into the hash of hashes
|
85
|
+
@attachments_hash[value] = element
|
86
|
+
else
|
87
|
+
# - { name: 'Low', color: '#306d8c' }
|
88
|
+
value = stringify_value_if_necessary(element)
|
89
|
+
end
|
90
|
+
|
91
|
+
file.puts(" - #{value}")
|
77
92
|
end
|
78
93
|
end
|
79
94
|
|
80
95
|
def stringify_value_if_necessary(value)
|
81
|
-
|
82
|
-
|
96
|
+
begin
|
97
|
+
return "'#{value}'" if value.include?(':')
|
98
|
+
|
99
|
+
value
|
100
|
+
rescue NoMethodError
|
101
|
+
value
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def is_this_is_an_attachment?(value)
|
106
|
+
is_hash = value.class.name == 'Hash'
|
107
|
+
return false unless is_hash
|
108
|
+
|
109
|
+
value.keys.map(&:to_s).include?('filename')
|
110
|
+
end
|
111
|
+
|
112
|
+
def setup_directories
|
113
|
+
Dir.mkdir('_data') unless File.exists?('_data')
|
114
|
+
Dir.mkdir('_data/airtable') unless File.exists?('_data/airtable')
|
115
|
+
|
116
|
+
Dir.mkdir('collections') unless File.exists?('collections')
|
117
|
+
end
|
118
|
+
|
119
|
+
def write_attachments_data_file
|
120
|
+
File.open("_data/airtable/attachments.yml", "w") do |f|
|
121
|
+
f.write(@attachments_hash.to_yaml)
|
122
|
+
end
|
83
123
|
end
|
84
124
|
end
|
85
125
|
end
|