cloudcannon-jekyll 3.2.3 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +8 -0
- data/lib/cloudcannon-jekyll/generators/collections.rb +77 -35
- data/lib/cloudcannon-jekyll/logger.rb +4 -0
- data/lib/cloudcannon-jekyll/version.rb +1 -1
- data/script/test-all-versions +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c513d1410254af59fed1d369d9852c77b0aa59474cf374f538a6557e5d0445f3
|
4
|
+
data.tar.gz: bfdcbdf270b02d3ab9f5b8c869650f46c4f8eb06a73f30f821fbeb9611fe0480
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dbf04c9447ce64b41394dfc7ed33924f089542506a054a46da581940efe44be5e2f7bca61014855dacb62efc46d86bdc3e9ac37e470f7c94f411aeec54bf05c
|
7
|
+
data.tar.gz: 9993038e810b3509f39aeadb41e77d2b29635481469c331daed39ce0154b5a8c2320fed85c301fc182088de93eb6a74b3f77eb5bd1c5ce574c65017567f4e811
|
data/HISTORY.md
CHANGED
@@ -20,13 +20,11 @@ module CloudCannonJekyll
|
|
20
20
|
@data_dir = Paths.data_dir(site)
|
21
21
|
@split_posts = group_by_category_folder(all_posts, 'posts')
|
22
22
|
@split_drafts = group_by_category_folder(all_drafts, 'drafts')
|
23
|
-
@uses_jekyll_paginate_v2 = defined?(Jekyll::PaginateV2::Generator::PaginationPage) == 'constant'
|
24
23
|
end
|
25
24
|
|
26
25
|
def generate_collections_config
|
27
26
|
collections = @site.config['collections'] || {}
|
28
|
-
|
29
|
-
collections_config = input_collections_config.reject { |_, v| v == false }
|
27
|
+
collections_config = @config['collections_config'] || {}
|
30
28
|
|
31
29
|
return collections_config if @config['collections_config_override']
|
32
30
|
|
@@ -55,11 +53,9 @@ module CloudCannonJekyll
|
|
55
53
|
}
|
56
54
|
end
|
57
55
|
|
58
|
-
collection_keys = (defaults.keys + collections.keys).uniq
|
56
|
+
collection_keys = (collections_config.keys + defaults.keys + collections.keys).uniq
|
59
57
|
|
60
58
|
collection_keys.each do |key|
|
61
|
-
next if input_collections_config[key] == false
|
62
|
-
|
63
59
|
processed = (defaults[key] || {})
|
64
60
|
.merge(collections[key] || {})
|
65
61
|
.merge(collections_config[key] || {})
|
@@ -75,8 +71,6 @@ module CloudCannonJekyll
|
|
75
71
|
end
|
76
72
|
|
77
73
|
@split_posts.each_key do |key|
|
78
|
-
next if input_collections_config[key] == false
|
79
|
-
|
80
74
|
posts_path = @split_posts[key]&.first&.relative_path&.sub(%r{(^|/)_posts.*}, '\1_posts')
|
81
75
|
next unless posts_path
|
82
76
|
|
@@ -90,8 +84,6 @@ module CloudCannonJekyll
|
|
90
84
|
end
|
91
85
|
|
92
86
|
@split_drafts.each_key do |key|
|
93
|
-
next if input_collections_config[key] == false
|
94
|
-
|
95
87
|
drafts_path = @split_drafts[key]&.first&.relative_path&.sub(%r{(^|/)_drafts.*}, '\1_drafts')
|
96
88
|
next unless drafts_path
|
97
89
|
|
@@ -115,33 +107,53 @@ module CloudCannonJekyll
|
|
115
107
|
paths.empty? ? [File.join('/', @collections_dir, '_drafts')] : paths
|
116
108
|
end
|
117
109
|
|
110
|
+
def each_document(&block)
|
111
|
+
@site.pages.each(&block)
|
112
|
+
@site.static_files.each(&block)
|
113
|
+
@site.collections.each_value { |coll| coll.docs.each(&block) }
|
114
|
+
all_drafts.each(&block)
|
115
|
+
|
116
|
+
# Jekyll 2.x.x doesn't have posts in site.collections
|
117
|
+
all_posts.each(&block) if IS_JEKYLL_2_X_X
|
118
|
+
end
|
119
|
+
|
118
120
|
def generate_collections(collections_config)
|
121
|
+
assigned_pages = {}
|
119
122
|
collections = {}
|
120
123
|
|
121
|
-
|
122
|
-
|
124
|
+
path_map = collections_config_path_map(collections_config)
|
125
|
+
|
126
|
+
each_document do |doc|
|
127
|
+
next unless allowed_document?(doc)
|
128
|
+
|
129
|
+
key = document_collection_key(doc, path_map)
|
130
|
+
|
131
|
+
unless key
|
132
|
+
Logger.warn "⚠️ No collection for #{doc.relative_path.bold}"
|
133
|
+
next
|
134
|
+
end
|
135
|
+
|
136
|
+
if collections_config.dig(key, 'parser') == false
|
137
|
+
Logger.warn "⚠️ Ignoring #{doc.relative_path.bold} in #{key.bold} collection"
|
138
|
+
next
|
139
|
+
end
|
123
140
|
|
124
141
|
collections[key] ||= []
|
142
|
+
collections[key].push(document_to_json(doc, key))
|
125
143
|
|
126
|
-
|
144
|
+
assigned_pages[doc.relative_path] = true if doc.instance_of?(Jekyll::Page)
|
145
|
+
end
|
127
146
|
|
128
|
-
|
129
|
-
|
130
|
-
elsif key == 'drafts' || key.end_with?('/drafts')
|
131
|
-
@split_drafts[key]
|
132
|
-
else
|
133
|
-
@site.collections[key]&.docs
|
134
|
-
end
|
147
|
+
collections_config.each_key do |key|
|
148
|
+
next if key == 'data'
|
135
149
|
|
136
150
|
collections[key] ||= []
|
137
|
-
collections[key] = collections[key].map do |doc|
|
138
|
-
document_to_json(doc, key)
|
139
|
-
end
|
140
151
|
end
|
141
152
|
|
142
153
|
if collections.key?('pages') && collections['pages'].empty?
|
143
|
-
|
144
|
-
|
154
|
+
all_pages.each do |page|
|
155
|
+
assigned = assigned_pages[page.relative_path]
|
156
|
+
collections['pages'].push(document_to_json(page, 'pages')) unless assigned
|
145
157
|
end
|
146
158
|
end
|
147
159
|
|
@@ -153,7 +165,7 @@ module CloudCannonJekyll
|
|
153
165
|
should_delete = if key == 'data'
|
154
166
|
!data_files?
|
155
167
|
else
|
156
|
-
collections[key]
|
168
|
+
collections[key]&.empty? && collection_config['auto_discovered']
|
157
169
|
end
|
158
170
|
|
159
171
|
if should_delete
|
@@ -178,6 +190,27 @@ module CloudCannonJekyll
|
|
178
190
|
end
|
179
191
|
end
|
180
192
|
|
193
|
+
def collections_config_path_map(collections_config)
|
194
|
+
unsorted = collections_config.map do |key, collection_config|
|
195
|
+
{
|
196
|
+
key: key,
|
197
|
+
path: "/#{collection_config['path']}/".sub(%r{/+}, '/')
|
198
|
+
}
|
199
|
+
end
|
200
|
+
|
201
|
+
unsorted.sort_by { |pair| pair[:path].length }.reverse
|
202
|
+
end
|
203
|
+
|
204
|
+
def document_collection_key(doc, path_map)
|
205
|
+
path = "/#{File.join(@collections_dir, doc.relative_path)}/".sub(%r{/+}, '/')
|
206
|
+
|
207
|
+
collection_path_pair = path_map.find do |pair|
|
208
|
+
path.start_with? pair[:path]
|
209
|
+
end
|
210
|
+
|
211
|
+
collection_path_pair[:key] if collection_path_pair
|
212
|
+
end
|
213
|
+
|
181
214
|
def legacy_document_data(doc)
|
182
215
|
legacy_data = {}
|
183
216
|
legacy_data['categories'] = doc.categories if doc.respond_to?(:categories)
|
@@ -215,9 +248,6 @@ module CloudCannonJekyll
|
|
215
248
|
def document_path(doc)
|
216
249
|
path = if doc.respond_to?(:collection) && doc.collection
|
217
250
|
File.join(@collections_dir, doc.relative_path)
|
218
|
-
elsif @uses_jekyll_paginate_v2 && doc.is_a?(Jekyll::PaginateV2::Generator::PaginationPage)
|
219
|
-
parts = doc.relative_path.split(File::SEPARATOR).drop(1)
|
220
|
-
File.join('/', *parts)
|
221
251
|
else
|
222
252
|
doc.relative_path
|
223
253
|
end
|
@@ -251,15 +281,27 @@ module CloudCannonJekyll
|
|
251
281
|
end
|
252
282
|
|
253
283
|
def all_pages
|
254
|
-
|
255
|
-
|
256
|
-
|
284
|
+
pages = @site.pages.select { |doc| allowed_page?(doc) }
|
285
|
+
static_pages = @site.static_files.select { |doc| allowed_static_file?(doc) }
|
286
|
+
pages + static_pages
|
287
|
+
end
|
257
288
|
|
258
|
-
|
259
|
-
|
289
|
+
def allowed_document?(doc)
|
290
|
+
if doc.instance_of?(Jekyll::Page)
|
291
|
+
allowed_page?(doc)
|
292
|
+
elsif doc.instance_of?(Jekyll::StaticFile)
|
293
|
+
allowed_static_file?(doc)
|
294
|
+
else
|
295
|
+
true
|
260
296
|
end
|
297
|
+
end
|
298
|
+
|
299
|
+
def allowed_page?(page)
|
300
|
+
page.html? || page.url.end_with?('/')
|
301
|
+
end
|
261
302
|
|
262
|
-
|
303
|
+
def allowed_static_file?(static_file)
|
304
|
+
STATIC_EXTENSIONS.include?(static_file.extname)
|
263
305
|
end
|
264
306
|
|
265
307
|
def data_files?
|
data/script/test-all-versions
CHANGED
@@ -6,5 +6,5 @@ JEKYLL_VERSION=2.4.0 bundle update && $(dirname "$0")/test &&
|
|
6
6
|
JEKYLL_VERSION=3.0.0 bundle update && $(dirname "$0")/test &&
|
7
7
|
JEKYLL_VERSION=3.3.1 bundle update && $(dirname "$0")/test &&
|
8
8
|
JEKYLL_VERSION=3.8.5 bundle update && $(dirname "$0")/test &&
|
9
|
-
JEKYLL_VERSION=4.
|
9
|
+
JEKYLL_VERSION=4.3.1 bundle update && $(dirname "$0")/test
|
10
10
|
|
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:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CloudCannon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|