cloudcannon-jekyll 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.reek.yml +6 -0
- data/HISTORY.md +4 -0
- data/lib/cloudcannon-jekyll.rb +1 -1
- data/lib/cloudcannon-jekyll/_cloudcannon/config-2.x.json +1 -1
- data/lib/cloudcannon-jekyll/_cloudcannon/config-3.0-4.x.json +1 -1
- data/lib/cloudcannon-jekyll/_cloudcannon/config.json +1 -1
- data/lib/cloudcannon-jekyll/configuration.rb +1 -0
- data/lib/cloudcannon-jekyll/generator.rb +9 -8
- data/lib/cloudcannon-jekyll/jsonify-filter.rb +74 -60
- data/lib/cloudcannon-jekyll/page-without-a-file.rb +1 -0
- data/lib/cloudcannon-jekyll/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db495486f69fc156d24ba59209fb5f1627e6692e500d7175daf0f393634339b4
|
4
|
+
data.tar.gz: 3baa3ab9dec30d4d2f834c14b6088780f22365a3bece79cf2a70428a225ed67e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5716ed9e99d8e57681880932c10c2f18eb0cfab47b82bb269ba544e67b4819fee5fe4a20deb03371c160d920b38acdd4356afe79ad5fe76b67c89b2059fd4bb4
|
7
|
+
data.tar.gz: cb4af8135d9426e12bf16532835ec31c01081f22ba5cfa9fecd80a7e8643136c5c2d0242cd99eb573f7c55079466ae9c032a93a1be32827cc7e6b0802af8f941
|
data/.reek.yml
ADDED
data/HISTORY.md
CHANGED
data/lib/cloudcannon-jekyll.rb
CHANGED
@@ -10,9 +10,9 @@ require_relative "cloudcannon-jekyll/version"
|
|
10
10
|
|
11
11
|
Liquid::Template.register_filter(CloudCannonJekyll::JsonifyFilter)
|
12
12
|
|
13
|
-
# Hooks didn't exist in Jekyll 2 so we monkey patch to get an :after_reset hook
|
14
13
|
if Jekyll::VERSION.start_with? "2"
|
15
14
|
module Jekyll
|
15
|
+
# Hooks didn't exist in Jekyll 2 so we monkey patch to get an :after_reset hook
|
16
16
|
class Site
|
17
17
|
alias_method :jekyll_reset, :reset
|
18
18
|
|
@@ -29,7 +29,7 @@
|
|
29
29
|
"includes": {{ config.includes_dir | cc_jsonify }},
|
30
30
|
"layouts": {{ config.layouts_dir | cc_jsonify }}
|
31
31
|
},
|
32
|
-
{% if config._array_structures %}"array-structures": {{ config._array_structures | cc_jsonify }},{% endif %}
|
32
|
+
{% if config._array_structures %}"array-structures": {{ config._array_structures | cc_jsonify: nil, 20 }},{% endif %}
|
33
33
|
{% assign select_data = config | cc_select_data_jsonify %}{% if select_data %}"select-data": {{ select_data }},{% endif %}
|
34
34
|
"source": {{ config.source | replace: pwd, "" | cc_jsonify }}
|
35
35
|
}
|
@@ -29,7 +29,7 @@
|
|
29
29
|
"includes": {{ config.includes_dir | cc_jsonify }},
|
30
30
|
"layouts": {{ config.layouts_dir | cc_jsonify }}
|
31
31
|
},
|
32
|
-
{% if config._array_structures %}"array-structures": {{ config._array_structures | cc_jsonify }},{% endif %}
|
32
|
+
{% if config._array_structures %}"array-structures": {{ config._array_structures | cc_jsonify: nil, 20 }},{% endif %}
|
33
33
|
{% assign select_data = config | cc_select_data_jsonify %}{% if select_data %}"select-data": {{ select_data }},{% endif %}
|
34
34
|
"source": {{ config.source | replace: pwd, "" | cc_jsonify }}
|
35
35
|
}
|
@@ -48,7 +48,7 @@
|
|
48
48
|
"layouts": {{ config.layouts_dir | cc_jsonify }}
|
49
49
|
},
|
50
50
|
{% if config._array_structures -%}
|
51
|
-
"array-structures": {{ config._array_structures | cc_jsonify }},
|
51
|
+
"array-structures": {{ config._array_structures | cc_jsonify: nil, 20 }},
|
52
52
|
{%- endif %}
|
53
53
|
{% assign select_data = config | cc_select_data_jsonify -%}
|
54
54
|
{% if select_data -%}
|
@@ -4,6 +4,7 @@ require "jekyll"
|
|
4
4
|
require "fileutils"
|
5
5
|
|
6
6
|
module CloudCannonJekyll
|
7
|
+
# Generates JSON files containing build config and build output details
|
7
8
|
class Generator < Jekyll::Generator
|
8
9
|
priority :lowest
|
9
10
|
|
@@ -27,7 +28,7 @@ module CloudCannonJekyll
|
|
27
28
|
def generate_file(filename, data)
|
28
29
|
dest = destination_path(filename)
|
29
30
|
FileUtils.mkdir_p(File.dirname(dest))
|
30
|
-
File.open(dest, "w") { |
|
31
|
+
File.open(dest, "w") { |file| file.write(file_content(filename, data)) }
|
31
32
|
end
|
32
33
|
|
33
34
|
def version_path_suffix
|
@@ -50,13 +51,13 @@ module CloudCannonJekyll
|
|
50
51
|
end
|
51
52
|
|
52
53
|
def file_content(filename, data)
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
54
|
+
page = PageWithoutAFile.new(@site, File.dirname(__FILE__), "", path(filename))
|
55
|
+
page.content = File.read(source_path(filename))
|
56
|
+
page.data["layout"] = nil
|
57
|
+
page.data["sitemap"] = false
|
58
|
+
page.data["permalink"] = "/#{path(filename)}"
|
59
|
+
page.render({}, data)
|
60
|
+
page.output
|
60
61
|
end
|
61
62
|
end
|
62
63
|
end
|
@@ -3,7 +3,11 @@
|
|
3
3
|
require "jekyll"
|
4
4
|
|
5
5
|
module CloudCannonJekyll
|
6
|
+
# Filter for converting Jekyll objects into JSON
|
6
7
|
module JsonifyFilter
|
8
|
+
STATIC_EXTENSIONS = [".html", ".htm"].freeze
|
9
|
+
STATIC_PATHS = ["/robots.txt", "/sitemap.xml"].freeze
|
10
|
+
|
7
11
|
CC_JSONIFY_KEY_SWAPS = {
|
8
12
|
"collections" => {
|
9
13
|
"_sort_key" => "_sort-key",
|
@@ -41,103 +45,113 @@ module CloudCannonJekyll
|
|
41
45
|
@simple_types.include?(input.class) || [true, false].include?(input)
|
42
46
|
end
|
43
47
|
|
44
|
-
def self.static_file_to_json(input, depth)
|
48
|
+
def self.static_file_to_json(input, depth, max_depth)
|
45
49
|
out = [
|
46
|
-
"\"extname\": #{JsonifyFilter.to_json(input.extname, depth
|
47
|
-
"\"path\": #{JsonifyFilter.to_json(input.relative_path, depth
|
50
|
+
"\"extname\": #{JsonifyFilter.to_json(input.extname, depth, max_depth)}",
|
51
|
+
"\"path\": #{JsonifyFilter.to_json(input.relative_path, depth, max_depth)}",
|
48
52
|
]
|
49
53
|
|
50
54
|
# modified_time isn't defined in Jekyll 2.4.0
|
51
55
|
if input.respond_to? :modified_time
|
52
|
-
|
56
|
+
file_json = JsonifyFilter.to_json(input.modified_time, depth, max_depth)
|
57
|
+
out.push("\"modified_time\": #{file_json}")
|
53
58
|
end
|
54
59
|
|
55
60
|
"{#{out.join(",")}}"
|
56
61
|
end
|
57
62
|
|
58
|
-
def self.
|
63
|
+
def self.document_data_to_a(data, prevent, depth, max_depth)
|
59
64
|
prevent += %w(content output next previous excerpt)
|
60
65
|
|
61
|
-
data.
|
66
|
+
out = data.map do |key, value|
|
62
67
|
next if prevent.include? key
|
63
68
|
|
64
69
|
prevent.push key
|
65
|
-
|
70
|
+
"#{key.to_json}: #{JsonifyFilter.to_json(value, depth, max_depth)}"
|
66
71
|
end
|
67
72
|
|
68
|
-
|
73
|
+
out.compact
|
69
74
|
end
|
70
75
|
|
71
|
-
def self.legacy_post_to_json(input, depth)
|
76
|
+
def self.legacy_post_to_json(input, depth, max_depth)
|
72
77
|
prevent = %w(dir name path url date id categories tags)
|
73
78
|
|
74
79
|
out = [
|
75
|
-
"\"dir\": #{JsonifyFilter.to_json(input.dir, depth
|
76
|
-
"\"name\": #{JsonifyFilter.to_json(input.name, depth
|
77
|
-
"\"path\": #{JsonifyFilter.to_json(input.path, depth
|
78
|
-
"\"url\": #{JsonifyFilter.to_json(input.url, depth
|
79
|
-
"\"date\": #{JsonifyFilter.to_json(input.date, depth
|
80
|
-
"\"id\": #{JsonifyFilter.to_json(input.id, depth
|
81
|
-
"\"categories\": #{JsonifyFilter.to_json(input.categories, depth
|
82
|
-
"\"tags\": #{JsonifyFilter.to_json(input.tags, depth
|
80
|
+
"\"dir\": #{JsonifyFilter.to_json(input.dir, depth, max_depth)}",
|
81
|
+
"\"name\": #{JsonifyFilter.to_json(input.name, depth, max_depth)}",
|
82
|
+
"\"path\": #{JsonifyFilter.to_json(input.path, depth, max_depth)}",
|
83
|
+
"\"url\": #{JsonifyFilter.to_json(input.url, depth, max_depth)}",
|
84
|
+
"\"date\": #{JsonifyFilter.to_json(input.date, depth, max_depth)}",
|
85
|
+
"\"id\": #{JsonifyFilter.to_json(input.id, depth, max_depth)}",
|
86
|
+
"\"categories\": #{JsonifyFilter.to_json(input.categories, depth, max_depth)}",
|
87
|
+
"\"tags\": #{JsonifyFilter.to_json(input.tags, depth, max_depth)}",
|
83
88
|
]
|
84
89
|
|
85
|
-
JsonifyFilter.
|
90
|
+
out += JsonifyFilter.document_data_to_a(input.data, prevent, depth, max_depth)
|
91
|
+
"{#{out.join(",")}}"
|
86
92
|
end
|
87
93
|
|
88
|
-
def self.page_to_json(input, depth)
|
94
|
+
def self.page_to_json(input, depth, max_depth)
|
89
95
|
prevent = %w(dir name path url)
|
90
96
|
|
91
97
|
out = [
|
92
|
-
"\"dir\": #{JsonifyFilter.to_json(input.dir, depth
|
93
|
-
"\"name\": #{JsonifyFilter.to_json(input.name, depth
|
94
|
-
"\"path\": #{JsonifyFilter.to_json(input.path, depth
|
95
|
-
"\"url\": #{JsonifyFilter.to_json(input.url, depth
|
98
|
+
"\"dir\": #{JsonifyFilter.to_json(input.dir, depth, max_depth)}",
|
99
|
+
"\"name\": #{JsonifyFilter.to_json(input.name, depth, max_depth)}",
|
100
|
+
"\"path\": #{JsonifyFilter.to_json(input.path, depth, max_depth)}",
|
101
|
+
"\"url\": #{JsonifyFilter.to_json(input.url, depth, max_depth)}",
|
96
102
|
]
|
97
103
|
|
98
104
|
# Merge Jekyll Defaults into data for pages (missing at v3.8.5)
|
99
|
-
defaults = input.site.frontmatter_defaults.all(input.relative_path, :pages).tap do |
|
100
|
-
|
105
|
+
defaults = input.site.frontmatter_defaults.all(input.relative_path, :pages).tap do |default|
|
106
|
+
default.delete("date")
|
101
107
|
end
|
102
108
|
|
103
109
|
data = Jekyll::Utils.deep_merge_hashes(defaults, input.data)
|
104
|
-
|
110
|
+
|
111
|
+
out += JsonifyFilter.document_data_to_a(data, prevent, depth, max_depth)
|
112
|
+
"{#{out.join(",")}}"
|
105
113
|
end
|
106
114
|
|
107
|
-
def self.document_to_json(input, depth)
|
115
|
+
def self.document_to_json(input, depth, max_depth)
|
108
116
|
prevent = %w(dir id relative_path url collection)
|
117
|
+
path_json = JsonifyFilter.to_json(input.relative_path, depth, max_depth)
|
109
118
|
|
110
119
|
out = [
|
111
|
-
"\"path\": #{
|
112
|
-
"\"relative_path\": #{
|
113
|
-
"\"url\": #{JsonifyFilter.to_json(input.url, depth
|
120
|
+
"\"path\": #{path_json}",
|
121
|
+
"\"relative_path\": #{path_json}",
|
122
|
+
"\"url\": #{JsonifyFilter.to_json(input.url, depth, max_depth)}",
|
114
123
|
]
|
115
124
|
|
116
|
-
|
117
|
-
|
125
|
+
collection = input.collection
|
126
|
+
unless collection.nil?
|
127
|
+
collection_json = JsonifyFilter.to_json(collection.label, depth, max_depth)
|
128
|
+
out.push("\"collection\": #{collection_json}")
|
118
129
|
end
|
119
130
|
|
120
131
|
# id isn't defined in Jekyll 2.4.0
|
121
|
-
|
132
|
+
if input.respond_to? :id
|
133
|
+
out.push("\"id\": #{JsonifyFilter.to_json(input.id, depth, max_depth)}")
|
134
|
+
end
|
122
135
|
|
123
|
-
JsonifyFilter.
|
136
|
+
out += JsonifyFilter.document_data_to_a(input.data, prevent, depth, max_depth)
|
137
|
+
"{#{out.join(",")}}"
|
124
138
|
end
|
125
139
|
|
126
|
-
def self.array_to_json(input, depth, key_swaps = {})
|
140
|
+
def self.array_to_json(input, depth, max_depth, key_swaps = {})
|
127
141
|
array = input.map do |value|
|
128
|
-
JsonifyFilter.to_json(value, depth
|
142
|
+
JsonifyFilter.to_json(value, depth, max_depth, key_swaps)
|
129
143
|
end
|
130
144
|
|
131
145
|
"[#{array.join(",")}]"
|
132
146
|
end
|
133
147
|
|
134
|
-
def self.hash_to_json(input, depth, key_swaps = {})
|
135
|
-
|
148
|
+
def self.hash_to_json(input, depth, max_depth, key_swaps = {})
|
149
|
+
out = input.map do |key, value|
|
136
150
|
string_key = (key_swaps[key] || key).to_s.to_json
|
137
|
-
"#{string_key}: #{JsonifyFilter.to_json(value, depth
|
151
|
+
"#{string_key}: #{JsonifyFilter.to_json(value, depth, max_depth, key_swaps)}"
|
138
152
|
end
|
139
153
|
|
140
|
-
"{#{
|
154
|
+
"{#{out.join(",")}}"
|
141
155
|
end
|
142
156
|
|
143
157
|
def self.config_to_select_data_json(input, depth)
|
@@ -155,7 +169,7 @@ module CloudCannonJekyll
|
|
155
169
|
next if prevent.include? key
|
156
170
|
|
157
171
|
prevent.push key
|
158
|
-
"#{key.to_s.to_json}: #{JsonifyFilter.to_json(value, depth
|
172
|
+
"#{key.to_s.to_json}: #{JsonifyFilter.to_json(value, depth)}"
|
159
173
|
end
|
160
174
|
|
161
175
|
out.compact!
|
@@ -163,39 +177,39 @@ module CloudCannonJekyll
|
|
163
177
|
"{#{out.join(",")}}" if out.any?
|
164
178
|
end
|
165
179
|
|
166
|
-
def self.to_json(input, depth, key_swaps = {})
|
167
|
-
|
180
|
+
def self.to_json(input, depth, max_depth = 9, key_swaps = {})
|
181
|
+
depth += 1
|
182
|
+
|
183
|
+
if depth > max_depth || (depth > 2 && JsonifyFilter.document_type?(input))
|
168
184
|
'"MAXIMUM_DEPTH"'
|
169
185
|
elsif JsonifyFilter.simple_type?(input)
|
170
186
|
input.to_json
|
171
187
|
elsif input.is_a?(Jekyll::StaticFile)
|
172
|
-
JsonifyFilter.static_file_to_json(input, depth)
|
188
|
+
JsonifyFilter.static_file_to_json(input, depth, max_depth)
|
173
189
|
elsif input.is_a?(Jekyll::Page)
|
174
|
-
JsonifyFilter.page_to_json(input, depth)
|
190
|
+
JsonifyFilter.page_to_json(input, depth, max_depth)
|
175
191
|
elsif Jekyll::VERSION.start_with?("2.") && input.is_a?(Jekyll::Post)
|
176
|
-
JsonifyFilter.legacy_post_to_json(input, depth)
|
192
|
+
JsonifyFilter.legacy_post_to_json(input, depth, max_depth)
|
177
193
|
elsif input.is_a?(Jekyll::Document)
|
178
|
-
JsonifyFilter.document_to_json(input, depth)
|
194
|
+
JsonifyFilter.document_to_json(input, depth, max_depth)
|
179
195
|
elsif input.is_a?(Array)
|
180
|
-
JsonifyFilter.array_to_json(input, depth, key_swaps)
|
196
|
+
JsonifyFilter.array_to_json(input, depth, max_depth, key_swaps)
|
181
197
|
elsif input.is_a?(Hash)
|
182
|
-
JsonifyFilter.hash_to_json(input, depth, key_swaps)
|
198
|
+
JsonifyFilter.hash_to_json(input, depth, max_depth, key_swaps)
|
183
199
|
else
|
184
200
|
input.class.to_s.prepend("UNSUPPORTED:").to_json
|
185
201
|
end
|
186
202
|
end
|
187
203
|
|
188
204
|
def cc_static_files_jsonify(input)
|
189
|
-
out =
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
page.path != "/robots.txt" &&
|
194
|
-
page.path != "/sitemap.xml"
|
195
|
-
|
196
|
-
out.push(JsonifyFilter.to_json(page, 1))
|
205
|
+
out = input.map do |page|
|
206
|
+
next unless STATIC_EXTENSIONS.include?(page.extname) || STATIC_PATHS.include?(page.path)
|
207
|
+
|
208
|
+
JsonifyFilter.to_json(page, 1)
|
197
209
|
end
|
198
210
|
|
211
|
+
out.compact!
|
212
|
+
|
199
213
|
"[#{out.join(",")}]"
|
200
214
|
end
|
201
215
|
|
@@ -207,11 +221,11 @@ module CloudCannonJekyll
|
|
207
221
|
end
|
208
222
|
end
|
209
223
|
|
210
|
-
def cc_jsonify(input, key_swaps_key = nil)
|
224
|
+
def cc_jsonify(input, key_swaps_key = nil, max_depth = 8)
|
211
225
|
if CC_JSONIFY_KEY_SWAPS.key? key_swaps_key
|
212
|
-
JsonifyFilter.to_json(input, 0, CC_JSONIFY_KEY_SWAPS[key_swaps_key])
|
226
|
+
JsonifyFilter.to_json(input, 0, max_depth, CC_JSONIFY_KEY_SWAPS[key_swaps_key])
|
213
227
|
else
|
214
|
-
JsonifyFilter.to_json(input, 0)
|
228
|
+
JsonifyFilter.to_json(input, 0, max_depth)
|
215
229
|
end
|
216
230
|
end
|
217
231
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudcannon-jekyll
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CloudCannon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -108,6 +108,7 @@ extensions: []
|
|
108
108
|
extra_rdoc_files: []
|
109
109
|
files:
|
110
110
|
- ".gitignore"
|
111
|
+
- ".reek.yml"
|
111
112
|
- ".rspec"
|
112
113
|
- ".rubocop.yml"
|
113
114
|
- ".travis.yml"
|