cloudcannon-jekyll 3.2.4 → 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: 0136aa6c6cd6d254318f43c1f2eca85a938e6be5fd037e5aedcb315fa594928c
4
- data.tar.gz: 30e81c35553da31c3bfb5aeaa747a31f545942d5b4600a2ea8239cd5b39a15d6
3
+ metadata.gz: c513d1410254af59fed1d369d9852c77b0aa59474cf374f538a6557e5d0445f3
4
+ data.tar.gz: bfdcbdf270b02d3ab9f5b8c869650f46c4f8eb06a73f30f821fbeb9611fe0480
5
5
  SHA512:
6
- metadata.gz: 9dd73df6c6ee9afc0ff3932ad4d592fe5da17601fe870b27dc138ac2f17a89fba2f74cf8f3069ca6fe40f34fee5f1f4797a471b2a346153204f1335bba2199ae
7
- data.tar.gz: d2ccc7e9ca1fc3c0330d776e8b14dfa29ba9c47f0067393e3cc194e03948ce028d224294c8ceb5518bc07b9c30938fc0a7f98b3a8553294cc97d90dc333ade03
6
+ metadata.gz: 9dbf04c9447ce64b41394dfc7ed33924f089542506a054a46da581940efe44be5e2f7bca61014855dacb62efc46d86bdc3e9ac37e470f7c94f411aeec54bf05c
7
+ data.tar.gz: 9993038e810b3509f39aeadb41e77d2b29635481469c331daed39ce0154b5a8c2320fed85c301fc182088de93eb6a74b3f77eb5bd1c5ce574c65017567f4e811
data/HISTORY.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 4.0.0
2
+
3
+ * Assign files to collections based on paths rather than matching Jekyll collection
4
+
1
5
  # 3.2.4
2
6
 
3
7
  * Revert changes to Jekyll Paginate behaviour
@@ -24,8 +24,7 @@ module CloudCannonJekyll
24
24
 
25
25
  def generate_collections_config
26
26
  collections = @site.config['collections'] || {}
27
- input_collections_config = @config['collections_config'] || {}
28
- collections_config = input_collections_config.reject { |_, v| v == false }
27
+ collections_config = @config['collections_config'] || {}
29
28
 
30
29
  return collections_config if @config['collections_config_override']
31
30
 
@@ -54,11 +53,9 @@ module CloudCannonJekyll
54
53
  }
55
54
  end
56
55
 
57
- collection_keys = (defaults.keys + collections.keys).uniq
56
+ collection_keys = (collections_config.keys + defaults.keys + collections.keys).uniq
58
57
 
59
58
  collection_keys.each do |key|
60
- next if input_collections_config[key] == false
61
-
62
59
  processed = (defaults[key] || {})
63
60
  .merge(collections[key] || {})
64
61
  .merge(collections_config[key] || {})
@@ -74,8 +71,6 @@ module CloudCannonJekyll
74
71
  end
75
72
 
76
73
  @split_posts.each_key do |key|
77
- next if input_collections_config[key] == false
78
-
79
74
  posts_path = @split_posts[key]&.first&.relative_path&.sub(%r{(^|/)_posts.*}, '\1_posts')
80
75
  next unless posts_path
81
76
 
@@ -89,8 +84,6 @@ module CloudCannonJekyll
89
84
  end
90
85
 
91
86
  @split_drafts.each_key do |key|
92
- next if input_collections_config[key] == false
93
-
94
87
  drafts_path = @split_drafts[key]&.first&.relative_path&.sub(%r{(^|/)_drafts.*}, '\1_drafts')
95
88
  next unless drafts_path
96
89
 
@@ -114,33 +107,53 @@ module CloudCannonJekyll
114
107
  paths.empty? ? [File.join('/', @collections_dir, '_drafts')] : paths
115
108
  end
116
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
+
117
120
  def generate_collections(collections_config)
121
+ assigned_pages = {}
118
122
  collections = {}
119
123
 
120
- collections_config.each_key do |key|
121
- 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
122
140
 
123
141
  collections[key] ||= []
142
+ collections[key].push(document_to_json(doc, key))
124
143
 
125
- next if collections_config.dig(key, 'parser') == false
144
+ assigned_pages[doc.relative_path] = true if doc.instance_of?(Jekyll::Page)
145
+ end
126
146
 
127
- collections[key] = if key == 'posts' || key.end_with?('/posts')
128
- @split_posts[key]
129
- elsif key == 'drafts' || key.end_with?('/drafts')
130
- @split_drafts[key]
131
- else
132
- @site.collections[key]&.docs
133
- end
147
+ collections_config.each_key do |key|
148
+ next if key == 'data'
134
149
 
135
150
  collections[key] ||= []
136
- collections[key] = collections[key].map do |doc|
137
- document_to_json(doc, key)
138
- end
139
151
  end
140
152
 
141
153
  if collections.key?('pages') && collections['pages'].empty?
142
- collections['pages'] = all_pages.map do |doc|
143
- 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
144
157
  end
145
158
  end
146
159
 
@@ -152,7 +165,7 @@ module CloudCannonJekyll
152
165
  should_delete = if key == 'data'
153
166
  !data_files?
154
167
  else
155
- collections[key].empty? && collection_config['auto_discovered']
168
+ collections[key]&.empty? && collection_config['auto_discovered']
156
169
  end
157
170
 
158
171
  if should_delete
@@ -177,6 +190,27 @@ module CloudCannonJekyll
177
190
  end
178
191
  end
179
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
+
180
214
  def legacy_document_data(doc)
181
215
  legacy_data = {}
182
216
  legacy_data['categories'] = doc.categories if doc.respond_to?(:categories)
@@ -247,15 +281,27 @@ module CloudCannonJekyll
247
281
  end
248
282
 
249
283
  def all_pages
250
- html_pages = @site.pages.select do |page|
251
- page.html? || page.url.end_with?('/')
252
- 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
253
288
 
254
- static_pages = @site.static_files.select do |static_page|
255
- 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
256
296
  end
297
+ end
298
+
299
+ def allowed_page?(page)
300
+ page.html? || page.url.end_with?('/')
301
+ end
257
302
 
258
- html_pages + static_pages
303
+ def allowed_static_file?(static_file)
304
+ STATIC_EXTENSIONS.include?(static_file.extname)
259
305
  end
260
306
 
261
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.4'
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.4
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - CloudCannon
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-21 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
@@ -105,7 +105,7 @@ homepage: https://github.com/cloudcannon/cloudcannon-jekyll
105
105
  licenses:
106
106
  - MIT
107
107
  metadata: {}
108
- post_install_message:
108
+ post_install_message:
109
109
  rdoc_options: []
110
110
  require_paths:
111
111
  - lib
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  requirements: []
123
123
  rubygems_version: 3.1.6
124
- signing_key:
124
+ signing_key:
125
125
  specification_version: 4
126
126
  summary: CloudCannon Jekyll integration
127
127
  test_files: []