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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d93973921d4a4f673b82f8b23f7e67b563e550bf62708631310ad0cc92a21e9c
4
- data.tar.gz: c1fbf58e6378b8b66703a9f25d0db3e9399b3a5324605ef891aaf009799abe02
3
+ metadata.gz: c513d1410254af59fed1d369d9852c77b0aa59474cf374f538a6557e5d0445f3
4
+ data.tar.gz: bfdcbdf270b02d3ab9f5b8c869650f46c4f8eb06a73f30f821fbeb9611fe0480
5
5
  SHA512:
6
- metadata.gz: cf473d7f0222da25f2bfe7c3b04065b474fec51d9c2820e27966b5d50d49369e8f41c854ad19e21ae330a585869e08e724c9ee7daec1f8c0fb1db00612758a19
7
- data.tar.gz: ea1826a618609914b83cc038ee058e453e8ca60400bd36d454bee5a891932a6970a36ed1d26fead1b57ed358dbecc4e6544038175642d4745bd3656e57dc49a9
6
+ metadata.gz: 9dbf04c9447ce64b41394dfc7ed33924f089542506a054a46da581940efe44be5e2f7bca61014855dacb62efc46d86bdc3e9ac37e470f7c94f411aeec54bf05c
7
+ data.tar.gz: 9993038e810b3509f39aeadb41e77d2b29635481469c331daed39ce0154b5a8c2320fed85c301fc182088de93eb6a74b3f77eb5bd1c5ce574c65017567f4e811
data/HISTORY.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 4.0.0
2
+
3
+ * Assign files to collections based on paths rather than matching Jekyll collection
4
+
5
+ # 3.2.4
6
+
7
+ * Revert changes to Jekyll Paginate behaviour
8
+
1
9
  # 3.2.3
2
10
 
3
11
  * Fixed malformed paths on index pages caused by jekyll-paginate-v2
@@ -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
- input_collections_config = @config['collections_config'] || {}
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
- collections_config.each_key do |key|
122
- next if key == 'data'
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
- next if collections_config.dig(key, 'parser') == false
144
+ assigned_pages[doc.relative_path] = true if doc.instance_of?(Jekyll::Page)
145
+ end
127
146
 
128
- collections[key] = if key == 'posts' || key.end_with?('/posts')
129
- @split_posts[key]
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
- collections['pages'] = all_pages.map do |doc|
144
- document_to_json(doc, 'pages')
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].empty? && collection_config['auto_discovered']
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
- html_pages = @site.pages.select do |page|
255
- page.html? || page.url.end_with?('/')
256
- end
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
- static_pages = @site.static_files.select do |static_page|
259
- STATIC_EXTENSIONS.include?(static_page.extname)
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
- html_pages + static_pages
303
+ def allowed_static_file?(static_file)
304
+ STATIC_EXTENSIONS.include?(static_file.extname)
263
305
  end
264
306
 
265
307
  def data_files?
@@ -8,5 +8,9 @@ module CloudCannonJekyll
8
8
  def self.info(str)
9
9
  Jekyll.logger.info('CloudCannon:', str)
10
10
  end
11
+
12
+ def self.warn(str)
13
+ Jekyll.logger.warn('CloudCannon:', str)
14
+ end
11
15
  end
12
16
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CloudCannonJekyll
4
- VERSION = '3.2.3'
4
+ VERSION = '4.0.0'
5
5
  end
@@ -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.2.1 bundle update && $(dirname "$0")/test
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: 3.2.3
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: 2022-11-03 00:00:00.000000000 Z
11
+ date: 2023-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll