cloudcannon-jekyll 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa855266f0cf697d2c9933a087c363ee3f1b81659a71f0b9dbdc2d36d42d5c29
4
- data.tar.gz: d43d27f97b01e437f4ca6e4f73b066cd7fa53aa67623637a43edfa6b9931cf28
3
+ metadata.gz: 34076270fab6ebafaa9530d0898bc08274f902cc86e6fb2e13890d4a69440854
4
+ data.tar.gz: 4036d2f037e7c36e31c112fcf4b296bd4afbb44f8d643aba36909108893b3b86
5
5
  SHA512:
6
- metadata.gz: 8e9dc486faa0469d5a93b68a48f8c9bbc36330db04e383ac6e801491581a768aa0c57705b09274a4585d1b796ae4b7a097d1209b17cfa6fc5150b57e680a7af9
7
- data.tar.gz: 37973b235d6ba9c4e30590d25b01de05cc027f90539ca51bc3438b1a09fc510323bbd19cb58e6083e89c683b27caab655f8be0233d6c27e8b282d4cf830f40cc
6
+ metadata.gz: 5ebaeaf4c7678a09859d0a845b1e4280c88ca1606099cf3e19ab7cc5a4d5a0ee2d2b18b5e827204d528915ed6d5281b089d9aa2baec4e0537d8efe5e0c263223
7
+ data.tar.gz: 63e881e3242696fa1faad9ae166a0e121ab58a5895782c2eb2d3c474401da7993c7a40cf138cb22195bfcdf8c092a3ba446f1de4f0fd1eb5b50ca0469b8e72c0
data/HISTORY.md CHANGED
@@ -1,3 +1,17 @@
1
+ # 2.1.0
2
+
3
+ * Add `_instance_values` to global scope
4
+
5
+ # 2.0.2
6
+
7
+ * Add `_enabled_editors` to global scope
8
+ * Increase max jsonify depth
9
+ * Remove unused key swaps
10
+
11
+ # 2.0.1
12
+
13
+ * Fix potential for null keys in cc_jsonify filter
14
+
1
15
  # 2.0.0
2
16
 
3
17
  * Rename a number of top level configuration keys to match source keys
@@ -17,7 +17,7 @@
17
17
  {% if config.timezone %}
18
18
  "timezone": {{ config.timezone | cc_jsonify }},
19
19
  {% endif %}
20
- "collections-config": {{ collections_config | cc_jsonify: 'collections' }},
20
+ "collections-config": {{ collections_config | cc_jsonify }},
21
21
  "collections": {
22
22
  "drafts": {{ drafts | cc_jsonify }},
23
23
  "posts": {{ site.posts | reverse | cc_jsonify }}{% if site.collections.size > 0 %},{% endif %}
@@ -26,16 +26,19 @@
26
26
  },
27
27
  "pages": {{ site.html_pages | cc_jsonify }},
28
28
  "static-pages": {{ site.static_files | cc_static_files_jsonify }},
29
- {% if site.cloudcannon.data.first %}{% assign data_seen = false %}
30
- "data": {
31
- {% for data in site.data %}{% assign key = data[0] %}{% if site.cloudcannon.data[key] %}{% if data_seen %},{% endif %}{{ data[0] | cc_jsonify }}: {{ data[1] | cc_jsonify }}{% assign data_seen = true %}{% endif %}{% endfor %}},
32
- {% elsif site.cloudcannon.data %}"data": {{ site.data | cc_jsonify }},{% endif %}
29
+ "data": {{ data | cc_jsonify }},
33
30
  {% if config.baseurl %}
34
31
  "base-url": {{ config.baseurl | cc_jsonify }},
35
32
  {% endif %}
36
33
  {% if config._comments %}
37
34
  "_comments": {{ config._comments | cc_jsonify }},
38
35
  {% endif %}
36
+ {% if config._enabled_editors %}
37
+ "_enabled_editors": {{ config._enabled_editors | cc_jsonify }},
38
+ {% endif %}
39
+ {% if config._instance_values %}
40
+ "_instance_values": {{ config._instance_values | cc_jsonify }},
41
+ {% endif %}
39
42
  {% if config._options %}
40
43
  "_options": {{ config._options | cc_jsonify }},
41
44
  {% endif %}
@@ -63,7 +66,7 @@
63
66
  "layouts": {{ config.layouts_dir | cc_jsonify }}
64
67
  },
65
68
  {% if config._array_structures %}
66
- "_array_structures": {{ config._array_structures | cc_jsonify: nil, 50 }},
69
+ "_array_structures": {{ config._array_structures | cc_jsonify: 50 }},
67
70
  {% endif %}
68
71
  {% assign select_data = config | cc_select_data_jsonify %}
69
72
  {% if select_data %}
@@ -17,7 +17,7 @@
17
17
  {% if config.timezone %}
18
18
  "timezone": {{ config.timezone | cc_jsonify }},
19
19
  {% endif %}
20
- "collections-config": {{ collections_config | cc_jsonify: 'collections' }},
20
+ "collections-config": {{ collections_config | cc_jsonify }},
21
21
  "collections": {
22
22
  "drafts": {{ drafts | cc_jsonify }}{% if site.collections.size > 0 %},{% endif %}
23
23
  {% for collection in site.collections %}"{{ collection.label | xml_escape }}": {{ collection.docs | cc_jsonify }}{% unless forloop.last %},{% endunless %}
@@ -25,16 +25,19 @@
25
25
  },
26
26
  "pages": {{ site.html_pages | cc_jsonify }},
27
27
  "static-pages": {{ site.static_files | cc_static_files_jsonify }},
28
- {% if site.cloudcannon.data.first %}{% assign data_seen = false %}
29
- "data": {
30
- {% for data in site.data %}{% assign key = data[0] %}{% if site.cloudcannon.data[key] %}{% if data_seen %},{% endif %}{{ data[0] | cc_jsonify }}: {{ data[1] | cc_jsonify }}{% assign data_seen = true %}{% endif %}{% endfor %}},
31
- {% elsif site.cloudcannon.data %}"data": {{ site.data | cc_jsonify }},{% endif %}
28
+ "data": {{ data | cc_jsonify }},
32
29
  {% if config.baseurl %}
33
30
  "base-url": {{ config.baseurl | cc_jsonify }},
34
31
  {% endif %}
35
32
  {% if config._comments %}
36
33
  "_comments": {{ config._comments | cc_jsonify }},
37
34
  {% endif %}
35
+ {% if config._enabled_editors %}
36
+ "_enabled_editors": {{ config._enabled_editors | cc_jsonify }},
37
+ {% endif %}
38
+ {% if config._instance_values %}
39
+ "_instance_values": {{ config._instance_values | cc_jsonify }},
40
+ {% endif %}
38
41
  {% if config._options %}
39
42
  "_options": {{ config._options | cc_jsonify }},
40
43
  {% endif %}
@@ -62,7 +65,7 @@
62
65
  "layouts": {{ config.layouts_dir | cc_jsonify }}
63
66
  },
64
67
  {% if config._array_structures %}
65
- "_array_structures": {{ config._array_structures | cc_jsonify: nil, 50 }},
68
+ "_array_structures": {{ config._array_structures | cc_jsonify: 50 }},
66
69
  {% endif %}
67
70
  {% assign select_data = config | cc_select_data_jsonify %}
68
71
  {% if select_data %}
@@ -17,7 +17,7 @@
17
17
  {% if config.timezone -%}
18
18
  "timezone": {{ config.timezone | cc_jsonify }},
19
19
  {%- endif %}
20
- "collections-config": {{ collections_config | cc_jsonify: 'collections' }},
20
+ "collections-config": {{ collections_config | cc_jsonify }},
21
21
  "collections": {
22
22
  "drafts": {{ drafts | cc_jsonify }}{% if site.collections.size > 0 %},{% endif %}
23
23
  {%- for collection in site.collections -%}
@@ -27,27 +27,19 @@
27
27
  },
28
28
  "pages": {{ site.html_pages | cc_jsonify }},
29
29
  "static-pages": {{ site.static_files | cc_static_files_jsonify }},
30
- {% if site.cloudcannon.data.first -%}
31
- "data": {
32
- {%- assign data_seen = false %}
33
- {%- for data in site.data %}
34
- {%- assign key = data[0] %}
35
- {%- if site.cloudcannon.data[key] %}
36
- {%- if data_seen %},{% endif -%}
37
- {{ data[0] | cc_jsonify }}: {{ data[1] | cc_jsonify }}
38
- {%- assign data_seen = true %}
39
- {%- endif %}
40
- {%- endfor -%}
41
- },
42
- {% elsif site.cloudcannon.data -%}
43
- "data": {{ site.data | cc_jsonify }},
44
- {%- endif %}
30
+ "data": {{ data | cc_jsonify }},
45
31
  {% if config.baseurl -%}
46
32
  "base-url": {{ config.baseurl | cc_jsonify }},
47
33
  {%- endif %}
48
34
  {% if config._comments -%}
49
35
  "_comments": {{ config._comments | cc_jsonify }},
50
36
  {%- endif %}
37
+ {% if config._enabled_editors -%}
38
+ "_enabled_editors": {{ config._enabled_editors | cc_jsonify }},
39
+ {%- endif %}
40
+ {% if config._instance_values -%}
41
+ "_instance_values": {{ config._instance_values | cc_jsonify }},
42
+ {%- endif %}
51
43
  {% if config._options -%}
52
44
  "_options": {{ config._options | cc_jsonify }},
53
45
  {%- endif %}
@@ -75,7 +67,7 @@
75
67
  "layouts": {{ config.layouts_dir | cc_jsonify }}
76
68
  },
77
69
  {% if config._array_structures -%}
78
- "_array_structures": {{ config._array_structures | cc_jsonify: nil, 50 }},
70
+ "_array_structures": {{ config._array_structures | cc_jsonify: 50 }},
79
71
  {%- endif %}
80
72
  {% assign select_data = config | cc_select_data_jsonify -%}
81
73
  {% if select_data -%}
@@ -18,6 +18,7 @@ module CloudCannonJekyll
18
18
  @reader = Reader.new(@site)
19
19
 
20
20
  collections_config = process_collections_config
21
+ data = process_data
21
22
 
22
23
  payload = @site.site_payload.merge({
23
24
  "gem_version" => CloudCannonJekyll::VERSION,
@@ -33,6 +34,7 @@ module CloudCannonJekyll
33
34
  "config" => @site.config,
34
35
  "collections_config" => collections_config,
35
36
  "drafts" => drafts,
37
+ "data" => data,
36
38
  }))
37
39
  end
38
40
 
@@ -55,6 +57,20 @@ module CloudCannonJekyll
55
57
  @site.config["collections_dir"] || ""
56
58
  end
57
59
 
60
+ def process_data
61
+ cc_data = @site.config.dig("cloudcannon", "data")
62
+ data = if cc_data == true
63
+ @site.data&.dup
64
+ elsif cc_data&.is_a?(Hash)
65
+ @site.data&.select { |key, _| cc_data.key?(key) }
66
+ end
67
+
68
+ data ||= {}
69
+ data["categories"] ||= @site.categories.keys
70
+ data["tags"] ||= @site.tags.keys
71
+ data
72
+ end
73
+
58
74
  def data_dir
59
75
  @site.config["data_dir"] || "_data"
60
76
  end
@@ -7,19 +7,6 @@ module CloudCannonJekyll
7
7
  module JsonifyFilter
8
8
  STATIC_EXTENSIONS = [".html", ".htm"].freeze
9
9
 
10
- CC_JSONIFY_KEY_SWAPS = {
11
- "collections" => {
12
- "_sort_key" => "_sort-key",
13
- "_subtext_key" => "_subtext-key",
14
- "_image_key" => "_image-key",
15
- "_image_size" => "_image-size",
16
- "_singular_name" => "_singular-name",
17
- "_singular_key" => "_singular-key",
18
- "_disable_add" => "_disable-add",
19
- "_add_options" => "_add-options",
20
- },
21
- }.freeze
22
-
23
10
  @simple_types = [
24
11
  String,
25
12
  Numeric,
@@ -60,7 +47,7 @@ module CloudCannonJekyll
60
47
  prevent += %w(content output next previous excerpt)
61
48
 
62
49
  out = data.map do |key, value|
63
- next if prevent.include? key
50
+ next if prevent.include?(key) || key.nil?
64
51
 
65
52
  prevent.push key
66
53
  next_max_depth = key == "_array_structures" ? 20 : max_depth
@@ -137,19 +124,19 @@ module CloudCannonJekyll
137
124
  "{#{out.join(",")}}"
138
125
  end
139
126
 
140
- def self.array_to_json(input, depth, max_depth, key_swaps = {})
127
+ def self.array_to_json(input, depth, max_depth)
141
128
  array = input.map do |value|
142
- JsonifyFilter.to_json(value, depth, max_depth, key_swaps)
129
+ JsonifyFilter.to_json(value, depth, max_depth)
143
130
  end
144
131
 
145
132
  "[#{array.join(",")}]"
146
133
  end
147
134
 
148
- def self.hash_to_json(input, depth, max_depth, key_swaps = {})
135
+ def self.hash_to_json(input, depth, max_depth)
149
136
  out = input.map do |key, value|
150
137
  next_max_depth = key == "_array_structures" ? 20 : max_depth
151
- string_key = (key_swaps[key] || key).to_s.to_json
152
- "#{string_key}: #{JsonifyFilter.to_json(value, depth, next_max_depth, key_swaps)}"
138
+ string_key = key.to_s.to_json
139
+ "#{string_key}: #{JsonifyFilter.to_json(value, depth, next_max_depth)}"
153
140
  end
154
141
 
155
142
  "{#{out.join(",")}}"
@@ -163,11 +150,11 @@ module CloudCannonJekyll
163
150
  baseurl show_dir_listing permalink paginate_path timezone quiet verbose defaults
164
151
  liquid kramdown title url description uploads_dir _comments _options _editor
165
152
  _explore _source_editor _array_structures maruku redcloth rdiscount redcarpet
166
- gems plugins cloudcannon _collection_groups)
153
+ gems plugins cloudcannon _collection_groups _enabled_editors _instance_values)
167
154
 
168
155
  out = input.map do |key, value|
169
156
  next unless value.is_a?(Array) || value.is_a?(Hash)
170
- next if prevent.include? key
157
+ next if prevent.include?(key) || key.nil?
171
158
 
172
159
  prevent.push key
173
160
  "#{key.to_s.to_json}: #{JsonifyFilter.to_json(value, depth)}"
@@ -178,7 +165,7 @@ module CloudCannonJekyll
178
165
  "{#{out.join(",")}}" if out.any?
179
166
  end
180
167
 
181
- def self.to_json(input, depth, max_depth = 9, key_swaps = {})
168
+ def self.to_json(input, depth, max_depth = 12)
182
169
  depth += 1
183
170
 
184
171
  if depth > max_depth || (depth > 3 && JsonifyFilter.document_type?(input))
@@ -194,9 +181,9 @@ module CloudCannonJekyll
194
181
  elsif input.is_a?(Jekyll::Document)
195
182
  JsonifyFilter.document_to_json(input, depth, max_depth)
196
183
  elsif input.is_a?(Array)
197
- JsonifyFilter.array_to_json(input, depth, max_depth, key_swaps)
184
+ JsonifyFilter.array_to_json(input, depth, max_depth)
198
185
  elsif input.is_a?(Hash)
199
- JsonifyFilter.hash_to_json(input, depth, max_depth, key_swaps)
186
+ JsonifyFilter.hash_to_json(input, depth, max_depth)
200
187
  else
201
188
  input.class.to_s.prepend("UNSUPPORTED:").to_json
202
189
  end
@@ -220,12 +207,8 @@ module CloudCannonJekyll
220
207
  end
221
208
  end
222
209
 
223
- def cc_jsonify(input, key_swaps_key = nil, max_depth = 8)
224
- if CC_JSONIFY_KEY_SWAPS.key? key_swaps_key
225
- JsonifyFilter.to_json(input, 0, max_depth, CC_JSONIFY_KEY_SWAPS[key_swaps_key])
226
- else
227
- JsonifyFilter.to_json(input, 0, max_depth)
228
- end
210
+ def cc_jsonify(input, max_depth = 12)
211
+ JsonifyFilter.to_json(input, 0, max_depth)
229
212
  end
230
213
  end
231
214
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CloudCannonJekyll
4
- VERSION = "2.0.0"
4
+ VERSION = "2.2.0"
5
5
  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: 2.0.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - CloudCannon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-14 00:00:00.000000000 Z
11
+ date: 2021-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll