cloudcannon-jekyll 0.3.1 → 0.5.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: 83d8c10e1f93435eb7f8cf67d63b3cf94c35ca24a4f6b02de64c11925f829213
4
- data.tar.gz: 178b75ec1c4984773ef897967e7973997811806237deefeca61dc906ab7a1bc2
3
+ metadata.gz: cc22c88ec15a9239eac56578dd09204ddd1a27708cb41049ee4a8159d1edd6f2
4
+ data.tar.gz: af972170086e38401c6196e29525ee61cd1d2aea2a0bb2de244635619fadfdb4
5
5
  SHA512:
6
- metadata.gz: d38402f61598857b9b6dba32c67d1ca44dd575dd93591a4944af0bd52bc5fb322cb5b2c9013c534a6031bed72d17583288f699bfb92c1853182b1bf4152c48be
7
- data.tar.gz: 6a79c497b8718283e72d65a8b415d77808470777df547701a30f1f564fb5d5b73e20e5ba7be17868b542ab79cc16791f3cfd556e6fa20d5dde75031d52b62e66
6
+ metadata.gz: 93b5a09207c6295d0f72282449a1e78d62d2ecc014c9af3d44c524fb1d1d8a715de918e93271a740b85eb688fd817f980e6483b854e9664c73d001579a0c4053
7
+ data.tar.gz: 5825c1c3fd9762691cf2c30042084cae6d476615225bd254cf07cd0d9e130bb464a972b9dbb4145389ae8668825e8e83ddf9059596590204bd9b4759b583c0d3
data/.gitignore CHANGED
@@ -1,7 +1,7 @@
1
1
  Gemfile.lock
2
2
  spec/dest/
3
- spec/fixtures/.jekyll-cache/
4
- spec/fixtures/.jekyll-metadata
3
+ spec/fixtures/**/.jekyll-cache/
4
+ spec/fixtures/**/.jekyll-metadata
5
5
  spec/fixtures/_site/
6
6
  gemfiles/.bundle/
7
7
  gemfiles/*.gemfile.lock
data/HISTORY.md CHANGED
@@ -1,6 +1,34 @@
1
+ # 0.5.0
2
+
3
+ * Rename a number of top level configuration keys to match source keys
4
+ * Combine `details.json` and `config.json` into `info.json`
5
+ * Increase max depth for array structures defined outside of global
6
+
7
+ # 0.4.0
8
+
9
+ * Add `collections_dir` to details collection item paths
10
+ * Fix pages collection clash with built-in pages
11
+ * Fixed posts collection config data overwriting drafts data
12
+ * Force generator to run after other lowest priority plugins
13
+
14
+ # 0.3.4
15
+
16
+ * Re-add id field for documents
17
+ * Fix for potential nil reference
18
+
19
+ # 0.3.3
20
+
21
+ * Rework fallback for older versions of Jekyll when reading data, posts and drafts again
22
+
23
+ # 0.3.2
24
+
25
+ * Rework fallback for older versions of Jekyll when reading data, posts and drafts
26
+ * Fix deprecation warning for `posts.map`
27
+
1
28
  # 0.3.1
2
29
 
3
30
  * Fix for empty collection configurations
31
+ * Added max depth parameter for jsonify filter and increase it for array structures in config output
4
32
 
5
33
  # 0.3.0
6
34
 
@@ -13,7 +41,6 @@
13
41
  * Renamed static to static-pages in details and removed `robots.txt` and `sitemap.xml` exceptions
14
42
  * Add `url` to static-pages
15
43
  * Normalise `_path` in static-pages
16
- * Added max depth parameter for jsonify filter and increase it for array structures in config output
17
44
 
18
45
  # 0.2.2
19
46
 
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A Jekyll plugin to create CloudCannon editor details.
4
4
 
5
- [![Build Status](https://travis-ci.com/CloudCannon/cloudcannon-jekyll.svg?branch=master)](https://travis-ci.com/CloudCannon/cloudcannon-jekyll) [![Gem Version](https://badge.fury.io/rb/cloudcannon-jekyll.svg)](https://badge.fury.io/rb/cloudcannon-jekyll)
5
+ [![Build Status](https://travis-ci.com/CloudCannon/cloudcannon-jekyll.svg?branch=main)](https://travis-ci.com/CloudCannon/cloudcannon-jekyll) [![Gem Version](https://badge.fury.io/rb/cloudcannon-jekyll.svg)](https://badge.fury.io/rb/cloudcannon-jekyll)
6
6
 
7
7
  ## Usage
8
8
 
@@ -0,0 +1,76 @@
1
+ {
2
+ "time": {{ site.time | date_to_xmlschema | cc_jsonify }},
3
+ "cloudcannon": {
4
+ "name": "cloudcannon-jekyll",
5
+ "version": {{ gem_version | cc_jsonify }}
6
+ },
7
+ "generator": {
8
+ "name": "jekyll",
9
+ "version": {{ jekyll.version | cc_jsonify }},
10
+ "environment": {{ jekyll.env | cc_jsonify }},
11
+ "metadata": {
12
+ "markdown": {{ site.markdown | cc_jsonify }},
13
+ "kramdown": {{ site.kramdown | cc_jsonify }},
14
+ "commonmark": {{ site.commonmark | cc_jsonify }}
15
+ }
16
+ },
17
+ {% if config.timezone %}
18
+ "timezone": {{ config.timezone | cc_jsonify }},
19
+ {% endif %}
20
+ "collections-config": {{ collections_config | cc_jsonify: 'collections' }},
21
+ "collections": {
22
+ "drafts": {{ drafts | cc_jsonify }},
23
+ "posts": {{ site.posts | reverse | cc_jsonify }}{% if site.collections.size > 0 %},{% endif %}
24
+ {% for collection in site.collections %}"{{ collection[0] | xml_escape }}": {{ collection[1].docs | cc_jsonify }}{% unless forloop.last %},{% endunless %}
25
+ {% endfor %}
26
+ },
27
+ "pages": {{ site.html_pages | cc_jsonify }},
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 %}
33
+ {% if config.baseurl %}
34
+ "base-url": {{ config.baseurl | cc_jsonify }},
35
+ {% endif %}
36
+ {% if config._comments %}
37
+ "_comments": {{ config._comments | cc_jsonify }},
38
+ {% endif %}
39
+ {% if config._options %}
40
+ "_options": {{ config._options | cc_jsonify }},
41
+ {% endif %}
42
+ {% if config._collection_groups %}
43
+ "_collection_groups": {{ config._collection_groups | cc_jsonify }},
44
+ {% endif %}
45
+ {% if config._editor %}
46
+ "_editor": {
47
+ "default_path": {{ config._editor.default_path | cc_jsonify }}
48
+ },
49
+ {% endif %}
50
+ {% if config._source_editor %}
51
+ "_source_editor": {
52
+ "tab_size": {{ config._source_editor.tab_size | cc_jsonify }},
53
+ "show_gutter": {{ config._source_editor.show_gutter | cc_jsonify }},
54
+ "theme": {{ config._source_editor.theme | cc_jsonify }}
55
+ },
56
+ {% endif %}
57
+ "paths": {
58
+ "uploads": {{ config.uploads_dir | cc_jsonify }},
59
+ "data": {{ config.data_dir | cc_jsonify }},
60
+ "pages": "",
61
+ "collections": {{ config.collections_dir | cc_jsonify }},
62
+ "includes": {{ config.includes_dir | cc_jsonify }},
63
+ "layouts": {{ config.layouts_dir | cc_jsonify }}
64
+ },
65
+ {% if config._array_structures %}
66
+ "_array_structures": {{ config._array_structures | cc_jsonify: nil, 50 }},
67
+ {% endif %}
68
+ {% assign select_data = config | cc_select_data_jsonify %}
69
+ {% if select_data %}
70
+ "_select_data": {{ select_data }},
71
+ {% endif %}
72
+ {% if config.defaults %}
73
+ "defaults": {{ config.defaults | cc_jsonify }},
74
+ {% endif %}
75
+ "source": {{ config.source | replace: pwd, "" | cc_jsonify }}
76
+ }
@@ -0,0 +1,75 @@
1
+ {
2
+ "time": {{ site.time | date_to_xmlschema | cc_jsonify }},
3
+ "cloudcannon": {
4
+ "name": "cloudcannon-jekyll",
5
+ "version": {{ gem_version | cc_jsonify }}
6
+ },
7
+ "generator": {
8
+ "name": "jekyll",
9
+ "version": {{ jekyll.version | cc_jsonify }},
10
+ "environment": {{ jekyll.env | cc_jsonify }},
11
+ "metadata": {
12
+ "markdown": {{ site.markdown | cc_jsonify }},
13
+ "kramdown": {{ site.kramdown | cc_jsonify }},
14
+ "commonmark": {{ site.commonmark | cc_jsonify }}
15
+ }
16
+ },
17
+ {% if config.timezone %}
18
+ "timezone": {{ config.timezone | cc_jsonify }},
19
+ {% endif %}
20
+ "collections-config": {{ collections_config | cc_jsonify: 'collections' }},
21
+ "collections": {
22
+ "drafts": {{ drafts | cc_jsonify }}{% if site.collections.size > 0 %},{% endif %}
23
+ {% for collection in site.collections %}"{{ collection.label | xml_escape }}": {{ collection.docs | cc_jsonify }}{% unless forloop.last %},{% endunless %}
24
+ {% endfor %}
25
+ },
26
+ "pages": {{ site.html_pages | cc_jsonify }},
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 %}
32
+ {% if config.baseurl %}
33
+ "base-url": {{ config.baseurl | cc_jsonify }},
34
+ {% endif %}
35
+ {% if config._comments %}
36
+ "_comments": {{ config._comments | cc_jsonify }},
37
+ {% endif %}
38
+ {% if config._options %}
39
+ "_options": {{ config._options | cc_jsonify }},
40
+ {% endif %}
41
+ {% if config._collection_groups %}
42
+ "_collection_groups": {{ config._collection_groups | cc_jsonify }},
43
+ {% endif %}
44
+ {% if config._editor %}
45
+ "_editor": {
46
+ "default_path": {{ config._editor.default_path | cc_jsonify }}
47
+ },
48
+ {% endif %}
49
+ {% if config._source_editor %}
50
+ "_source_editor": {
51
+ "tab_size": {{ config._source_editor.tab_size | cc_jsonify }},
52
+ "show_gutter": {{ config._source_editor.show_gutter | cc_jsonify }},
53
+ "theme": {{ config._source_editor.theme | cc_jsonify }}
54
+ },
55
+ {% endif %}
56
+ "paths": {
57
+ "uploads": {{ config.uploads_dir | cc_jsonify }},
58
+ "data": {{ config.data_dir | cc_jsonify }},
59
+ "pages": "",
60
+ "collections": {{ config.collections_dir | cc_jsonify }},
61
+ "includes": {{ config.includes_dir | cc_jsonify }},
62
+ "layouts": {{ config.layouts_dir | cc_jsonify }}
63
+ },
64
+ {% if config._array_structures %}
65
+ "_array_structures": {{ config._array_structures | cc_jsonify: nil, 50 }},
66
+ {% endif %}
67
+ {% assign select_data = config | cc_select_data_jsonify %}
68
+ {% if select_data %}
69
+ "_select_data": {{ select_data }},
70
+ {% endif %}
71
+ {% if config.defaults %}
72
+ "defaults": {{ config.defaults | cc_jsonify }},
73
+ {% endif %}
74
+ "source": {{ config.source | replace: pwd, "" | cc_jsonify }}
75
+ }
@@ -0,0 +1,88 @@
1
+ {
2
+ "time": {{ site.time | date_to_xmlschema | cc_jsonify }},
3
+ "cloudcannon": {
4
+ "name": "cloudcannon-jekyll",
5
+ "version": {{ gem_version | cc_jsonify }}
6
+ },
7
+ "generator": {
8
+ "name": "jekyll",
9
+ "version": {{ jekyll.version | cc_jsonify }},
10
+ "environment": {{ jekyll.env | cc_jsonify }},
11
+ "metadata": {
12
+ "markdown": {{ site.markdown | cc_jsonify }},
13
+ "kramdown": {{ site.kramdown | cc_jsonify }},
14
+ "commonmark": {{ site.commonmark | cc_jsonify }}
15
+ }
16
+ },
17
+ {% if config.timezone -%}
18
+ "timezone": {{ config.timezone | cc_jsonify }},
19
+ {%- endif %}
20
+ "collections-config": {{ collections_config | cc_jsonify: 'collections' }},
21
+ "collections": {
22
+ "drafts": {{ drafts | cc_jsonify }}{% if site.collections.size > 0 %},{% endif %}
23
+ {%- for collection in site.collections -%}
24
+ "{{ collection.label | xml_escape }}": {{ collection.docs | cc_jsonify }}
25
+ {%- unless forloop.last %},{% endunless %}
26
+ {%- endfor -%}
27
+ },
28
+ "pages": {{ site.html_pages | cc_jsonify }},
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 %}
45
+ {% if config.baseurl -%}
46
+ "base-url": {{ config.baseurl | cc_jsonify }},
47
+ {%- endif %}
48
+ {% if config._comments -%}
49
+ "_comments": {{ config._comments | cc_jsonify }},
50
+ {%- endif %}
51
+ {% if config._options -%}
52
+ "_options": {{ config._options | cc_jsonify }},
53
+ {%- endif %}
54
+ {% if config._collection_groups -%}
55
+ "_collection_groups": {{ config._collection_groups | cc_jsonify }},
56
+ {%- endif %}
57
+ {% if config._editor -%}
58
+ "_editor": {
59
+ "default_path": {{ config._editor.default_path | cc_jsonify }}
60
+ },
61
+ {%- endif %}
62
+ {% if config._source_editor -%}
63
+ "_source_editor": {
64
+ "tab_size": {{ config._source_editor.tab_size | cc_jsonify }},
65
+ "show_gutter": {{ config._source_editor.show_gutter | cc_jsonify }},
66
+ "theme": {{ config._source_editor.theme | cc_jsonify }}
67
+ },
68
+ {%- endif %}
69
+ "paths": {
70
+ "uploads": {{ config.uploads_dir | cc_jsonify }},
71
+ "data": {{ config.data_dir | cc_jsonify }},
72
+ "pages": "",
73
+ "collections": {{ config.collections_dir | cc_jsonify }},
74
+ "includes": {{ config.includes_dir | cc_jsonify }},
75
+ "layouts": {{ config.layouts_dir | cc_jsonify }}
76
+ },
77
+ {% if config._array_structures -%}
78
+ "_array_structures": {{ config._array_structures | cc_jsonify: nil, 50 }},
79
+ {%- endif %}
80
+ {% assign select_data = config | cc_select_data_jsonify -%}
81
+ {% if select_data -%}
82
+ "_select_data": {{ select_data }},
83
+ {%- endif %}
84
+ {% if config.defaults -%}
85
+ "defaults": {{ config.defaults | cc_jsonify }},
86
+ {%- endif %}
87
+ "source": {{ config.source | replace: pwd, "" | cc_jsonify }}
88
+ }
@@ -7,18 +7,17 @@ require_relative "reader"
7
7
  module CloudCannonJekyll
8
8
  # Generates JSON files containing build config and build output details
9
9
  class Generator < Jekyll::Generator
10
+ # Override the Jekyll::Plugin spaceship to push our plugin to the very end
10
11
  priority :lowest
12
+ def self.<=>(*)
13
+ 1
14
+ end
11
15
 
12
16
  def generate(site)
13
17
  @site = site
14
18
  @reader = Reader.new(@site)
15
19
 
16
- collections_config = @site.config["collections"].dup || {}
17
-
18
- # Workaround for empty collection configurations
19
- collections_config.each_key do |key|
20
- collections_config[key] ||= { "output" => false }
21
- end
20
+ collections_config = process_collections_config
22
21
 
23
22
  payload = @site.site_payload.merge({
24
23
  "gem_version" => CloudCannonJekyll::VERSION,
@@ -27,16 +26,27 @@ module CloudCannonJekyll
27
26
  drafts = add_blogging_config(collections_config)
28
27
  add_collection_paths(collections_config)
29
28
  add_data_config(collections_config)
29
+ add_legacy_explore_groups
30
30
 
31
- generate_file("config", payload.merge({
32
- "pwd" => Dir.pwd,
33
- "config" => @site.config,
34
- "collections" => collections_config,
31
+ generate_file("info", payload.merge({
32
+ "pwd" => Dir.pwd,
33
+ "config" => @site.config,
34
+ "collections_config" => collections_config,
35
+ "drafts" => drafts,
35
36
  }))
37
+ end
36
38
 
37
- generate_file("details", payload.merge({
38
- "drafts" => drafts,
39
- }))
39
+ def process_collections_config
40
+ collections = @site.config["collections"]&.dup || {}
41
+ cc_collections = @site.config.dig("cloudcannon", "collections")&.dup || {}
42
+
43
+ collections.each_key do |key|
44
+ # Workaround for empty collection configurations
45
+ defaults = collections[key] || { "output" => false }
46
+ cc_collections[key] = (cc_collections[key] || {}).merge(defaults)
47
+ end
48
+
49
+ cc_collections
40
50
  end
41
51
 
42
52
  def collections_dir
@@ -49,11 +59,13 @@ module CloudCannonJekyll
49
59
  @site.config["data_dir"] || "_data"
50
60
  end
51
61
 
62
+ # rubocop:disable Metrics/AbcSize
52
63
  def add_category_folder_config(collections_config, posts_config = {})
53
64
  posts = @site.posts || @site.collections["posts"]
65
+ docs = posts.class.method_defined?(:docs) ? posts.docs : posts
54
66
  seen = {}
55
67
 
56
- posts.map do |post|
68
+ docs.map do |post|
57
69
  parts = post.relative_path.split("/_posts/")
58
70
  path = parts.first
59
71
 
@@ -68,23 +80,31 @@ module CloudCannonJekyll
68
80
  collections_path = "#{collections_dir}/#{folder}".gsub(%r!\/+!, "/").sub(%r!^\/+!, "")
69
81
 
70
82
  collections_config["#{folder}/posts"] = posts_config.merge({
71
- "_path" => "#{collections_path}/_posts",
83
+ "path" => "#{collections_path}/_posts",
72
84
  })
73
85
 
74
86
  # Adding the category draft config like this isn't ideal, since you could have drafts
75
87
  # without posts, but it's a decent trade off vs looking for _drafts folders
76
88
  collections_config["#{folder}/drafts"] = posts_config.merge({
77
- "_path" => "#{collections_path}/_drafts",
89
+ "path" => "#{collections_path}/_drafts",
78
90
  })
79
91
 
80
92
  path
81
93
  end
82
94
  end
95
+ # rubocop:enable Metrics/AbcSize
96
+
97
+ # Support for the deprecated _explore configuration
98
+ def add_legacy_explore_groups
99
+ unless @site.config.key?("_collection_groups")
100
+ @site.config["_collection_groups"] = @site.config.dig("_explore", "groups")&.dup
101
+ end
102
+ end
83
103
 
84
104
  # Add data to collections config if raw data files exist
85
105
  def add_data_config(collections_config)
86
106
  data_files = @reader.read_data(data_dir)
87
- collections_config["data"] = { "_path" => data_dir } if data_files&.keys&.any?
107
+ collections_config["data"] = { "path" => data_dir } if data_files&.keys&.any?
88
108
  end
89
109
 
90
110
  # Add posts/drafts to collections config
@@ -92,9 +112,7 @@ module CloudCannonJekyll
92
112
  collections_config["posts"] = { "output" => true } if Jekyll::VERSION.start_with? "2."
93
113
  drafts = @reader.read_drafts(collections_dir)
94
114
 
95
- if collections_config.key?("posts")
96
- collections_config["drafts"] = collections_config["posts"].dup
97
- elsif drafts.any?
115
+ if drafts.any? || (collections_config.key?("posts") && !collections_config.key?("drafts"))
98
116
  collections_config["drafts"] = {}
99
117
  end
100
118
 
@@ -106,12 +124,10 @@ module CloudCannonJekyll
106
124
  drafts
107
125
  end
108
126
 
109
- # Add _path to each collection config
127
+ # Add path to each collection config
110
128
  def add_collection_paths(collections_config)
111
129
  collections_config.each do |key, collection|
112
- next if collection.key?("_path")
113
-
114
- collection["_path"] = File.join(collections_dir, "_#{key}").sub(%r!^\/+!, "")
130
+ collection["path"] ||= File.join(collections_dir, "_#{key}").sub(%r!^\/+!, "")
115
131
  end
116
132
  end
117
133
 
@@ -64,7 +64,8 @@ module CloudCannonJekyll
64
64
  next if prevent.include? key
65
65
 
66
66
  prevent.push key
67
- "#{key.to_json}: #{JsonifyFilter.to_json(value, depth, max_depth)}"
67
+ next_max_depth = key == "_array_structures" ? 20 : max_depth
68
+ "#{key.to_json}: #{JsonifyFilter.to_json(value, depth, next_max_depth)}"
68
69
  end
69
70
 
70
71
  out.compact
@@ -107,20 +108,32 @@ module CloudCannonJekyll
107
108
  "{#{out.join(",")}}"
108
109
  end
109
110
 
111
+ def self.document_path(input)
112
+ collections_dir = input.site.config["collections_dir"] || ""
113
+ if input.collection && !collections_dir.empty?
114
+ "#{collections_dir}/#{input.relative_path}"
115
+ else
116
+ input.relative_path
117
+ end
118
+ end
119
+
110
120
  def self.document_to_json(input, depth, max_depth)
111
- prevent = %w(dir id relative_path url collection)
121
+ prevent = %w(dir relative_path url collection)
112
122
 
113
123
  out = [
114
- "\"path\": #{JsonifyFilter.to_json(input.relative_path, depth, max_depth)}",
124
+ "\"path\": #{JsonifyFilter.to_json(JsonifyFilter.document_path(input), depth, max_depth)}",
115
125
  "\"url\": #{JsonifyFilter.to_json(input.url, depth, max_depth)}",
116
126
  ]
117
127
 
118
- collection = input.collection
119
- unless collection.nil?
120
- collection_json = JsonifyFilter.to_json(collection.label, depth, max_depth)
128
+ unless input.collection.nil?
129
+ collection_json = JsonifyFilter.to_json(input.collection.label, depth, max_depth)
121
130
  out.push("\"collection\": #{collection_json}")
122
131
  end
123
132
 
133
+ if input.respond_to? :id
134
+ out.push("\"id\": #{JsonifyFilter.to_json(input.id, depth, max_depth)}")
135
+ end
136
+
124
137
  out += JsonifyFilter.document_data_to_a(input.data, prevent, depth, max_depth)
125
138
  "{#{out.join(",")}}"
126
139
  end
@@ -135,8 +148,9 @@ module CloudCannonJekyll
135
148
 
136
149
  def self.hash_to_json(input, depth, max_depth, key_swaps = {})
137
150
  out = input.map do |key, value|
151
+ next_max_depth = key == "_array_structures" ? 20 : max_depth
138
152
  string_key = (key_swaps[key] || key).to_s.to_json
139
- "#{string_key}: #{JsonifyFilter.to_json(value, depth, max_depth, key_swaps)}"
153
+ "#{string_key}: #{JsonifyFilter.to_json(value, depth, next_max_depth, key_swaps)}"
140
154
  end
141
155
 
142
156
  "{#{out.join(",")}}"
@@ -150,7 +164,7 @@ module CloudCannonJekyll
150
164
  baseurl show_dir_listing permalink paginate_path timezone quiet verbose defaults
151
165
  liquid kramdown title url description uploads_dir _comments _options _editor
152
166
  _explore _source_editor _array_structures maruku redcloth rdiscount redcarpet
153
- gems plugins)
167
+ gems plugins cloudcannon _collection_groups)
154
168
 
155
169
  out = input.map do |key, value|
156
170
  next unless value.is_a?(Array) || value.is_a?(Hash)
@@ -168,7 +182,7 @@ module CloudCannonJekyll
168
182
  def self.to_json(input, depth, max_depth = 9, key_swaps = {})
169
183
  depth += 1
170
184
 
171
- if depth > max_depth || (depth > 2 && JsonifyFilter.document_type?(input))
185
+ if depth > max_depth || (depth > 3 && JsonifyFilter.document_type?(input))
172
186
  '"MAXIMUM_DEPTH"'
173
187
  elsif JsonifyFilter.simple_type?(input)
174
188
  input.to_json
@@ -1,12 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "jekyll"
4
-
5
- if !Jekyll::VERSION.start_with? "2."
6
- require_relative "readers/data-reader"
7
- else
8
- require_relative "readers/old-data-reader"
9
- end
4
+ require_relative "readers/old-data-reader"
5
+ require_relative "readers/data-reader"
10
6
 
11
7
  module CloudCannonJekyll
12
8
  # Wraps read functions into one class
@@ -18,6 +14,7 @@ module CloudCannonJekyll
18
14
  end
19
15
 
20
16
  def read_data(dir = "_data")
17
+ # DataReader doesn't exist in old versions of Jekyll
21
18
  if Jekyll::VERSION.start_with? "2."
22
19
  CloudCannonJekyll::OldDataReader.new(@site).read(dir)
23
20
  else
@@ -26,6 +23,7 @@ module CloudCannonJekyll
26
23
  end
27
24
 
28
25
  def read_drafts(dir = "")
26
+ # PostReader doesn't exist in old versions of Jekyll
29
27
  if Jekyll::VERSION.start_with? "2."
30
28
  @site.read_content(dir, "_drafts", Jekyll::Draft)
31
29
  else
@@ -34,6 +32,7 @@ module CloudCannonJekyll
34
32
  end
35
33
 
36
34
  def read_posts(dir = "")
35
+ # PostReader doesn't exist in old versions of Jekyll
37
36
  if Jekyll::VERSION.start_with? "2."
38
37
  @site.read_content(dir, "_posts", Jekyll::Post)
39
38
  else
@@ -1,18 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "jekyll"
3
+ unless Jekyll::VERSION.start_with? "2."
4
+ require "jekyll"
4
5
 
5
- module CloudCannonJekyll
6
- # Reads data files and creates a collections-style hash representation
7
- class DataReader < Jekyll::DataReader
8
- # Determines how to read a data file.
9
- # This is overridden return a hash instead of reading the file.
10
- #
11
- # Returns a hash with the path to the data file.
12
- def read_data_file(path)
13
- {
14
- "path" => path,
15
- }
6
+ module CloudCannonJekyll
7
+ # Reads data files and creates a collections-style hash representation
8
+ class DataReader < Jekyll::DataReader
9
+ # Determines how to read a data file.
10
+ # This is overridden return a hash instead of reading the file.
11
+ #
12
+ # Returns a hash with the path to the data file.
13
+ def read_data_file(path)
14
+ {
15
+ "path" => path,
16
+ }
17
+ end
16
18
  end
17
19
  end
18
20
  end
@@ -1,55 +1,57 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "jekyll"
4
-
5
- module CloudCannonJekyll
6
- # Reads data files and creates a collections-style hash representation
7
- # Aims to replicate the data reading logic in Jekyll 2.5
8
- class OldDataReader
9
- attr_reader :site
10
-
11
- def initialize(site)
12
- @site = site
13
- @safe = site.safe
14
- @content = {}
15
- end
3
+ if Jekyll::VERSION.start_with? "2."
4
+ require "jekyll"
5
+
6
+ module CloudCannonJekyll
7
+ # Reads data files and creates a collections-style hash representation
8
+ # Aims to replicate the data reading logic in Jekyll 2.5
9
+ class OldDataReader
10
+ attr_reader :site
11
+
12
+ def initialize(site)
13
+ @site = site
14
+ @safe = site.safe
15
+ @content = {}
16
+ end
16
17
 
17
- def read(dir)
18
- base = Jekyll.sanitized_path(@site.source, dir)
19
- read_data_to(base, @content)
20
- @content
21
- end
18
+ def read(dir)
19
+ base = Jekyll.sanitized_path(@site.source, dir)
20
+ read_data_to(base, @content)
21
+ @content
22
+ end
22
23
 
23
- def read_data_to(dir, data)
24
- return unless File.directory?(dir) && (!@safe || !File.symlink?(dir))
24
+ def read_data_to(dir, data)
25
+ return unless File.directory?(dir) && (!@safe || !File.symlink?(dir))
25
26
 
26
- entries = Dir.chdir(dir) do
27
- Dir["*.{yaml,yml,json,csv}"] + Dir["*"].select { |fn| File.directory?(fn) }
28
- end
27
+ entries = Dir.chdir(dir) do
28
+ Dir["*.{yaml,yml,json,csv}"] + Dir["*"].select { |fn| File.directory?(fn) }
29
+ end
29
30
 
30
- entries.each do |entry|
31
- path = Jekyll.sanitized_path(dir, entry)
32
- next if File.symlink?(path) && @safe
31
+ entries.each do |entry|
32
+ path = Jekyll.sanitized_path(dir, entry)
33
+ next if File.symlink?(path) && @safe
33
34
 
34
- key = sanitize_filename(File.basename(entry, ".*"))
35
- if File.directory?(path)
36
- read_data_to(path, data[key] = {})
37
- else
38
- data[key] = read_data_file(path)
35
+ key = sanitize_filename(File.basename(entry, ".*"))
36
+ if File.directory?(path)
37
+ read_data_to(path, data[key] = {})
38
+ else
39
+ data[key] = read_data_file(path)
40
+ end
39
41
  end
40
42
  end
41
- end
42
43
 
43
- def read_data_file(path)
44
- {
45
- "path" => path,
46
- }
47
- end
44
+ def read_data_file(path)
45
+ {
46
+ "path" => path,
47
+ }
48
+ end
48
49
 
49
- def sanitize_filename(name)
50
- name.gsub!(%r![^\w\s_-]+!, "")
51
- name.gsub!(%r!(^|\b\s)\s+($|\s?\b)!, '\\1\\2')
52
- name.gsub(%r!\s+!, "_")
50
+ def sanitize_filename(name)
51
+ name.gsub!(%r![^\w\s_-]+!, "")
52
+ name.gsub!(%r!(^|\b\s)\s+($|\s?\b)!, '\\1\\2')
53
+ name.gsub(%r!\s+!, "_")
54
+ end
53
55
  end
54
56
  end
55
57
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CloudCannonJekyll
4
- VERSION = "0.3.1"
4
+ VERSION = "0.5.0"
5
5
  end
data/script/release CHANGED
@@ -11,10 +11,10 @@ cd $(dirname "$0")/..
11
11
  rm -rf cloudcannon-jekyll-*.gem
12
12
  gem build -q cloudcannon-jekyll.gemspec
13
13
 
14
- # Ensure we're on the master branch
14
+ # Ensure we're on the legacy branch
15
15
 
16
- (git branch | grep -q '* master') || {
17
- echo "Only release from the master branch."
16
+ (git branch | grep -q '* legacy') || {
17
+ echo "Only release from the legacy branch."
18
18
  exit 1
19
19
  }
20
20
 
@@ -34,6 +34,6 @@ git fetch -t origin
34
34
  # Push tag and upload new gem
35
35
 
36
36
  git tag "$tag" &&
37
- git push origin master &&
37
+ git push origin legacy &&
38
38
  git push origin "$tag" &&
39
39
  gem push cloudcannon-jekyll-*.gem
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: 0.3.1
4
+ version: 0.5.0
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-25 00:00:00.000000000 Z
11
+ date: 2021-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -120,12 +120,9 @@ files:
120
120
  - Rakefile
121
121
  - cloudcannon-jekyll.gemspec
122
122
  - lib/cloudcannon-jekyll.rb
123
- - lib/cloudcannon-jekyll/_cloudcannon/config-2.x.json
124
- - lib/cloudcannon-jekyll/_cloudcannon/config-3.0-4.x.json
125
- - lib/cloudcannon-jekyll/_cloudcannon/config.json
126
- - lib/cloudcannon-jekyll/_cloudcannon/details-2.x.json
127
- - lib/cloudcannon-jekyll/_cloudcannon/details-3.0-4.x.json
128
- - lib/cloudcannon-jekyll/_cloudcannon/details.json
123
+ - lib/cloudcannon-jekyll/_cloudcannon/info-2.x.json
124
+ - lib/cloudcannon-jekyll/_cloudcannon/info-3.0-4.x.json
125
+ - lib/cloudcannon-jekyll/_cloudcannon/info.json
129
126
  - lib/cloudcannon-jekyll/configuration.rb
130
127
  - lib/cloudcannon-jekyll/generator.rb
131
128
  - lib/cloudcannon-jekyll/jsonify-filter.rb
@@ -1,36 +0,0 @@
1
- {
2
- "time": {{ site.time | date_to_xmlschema | cc_jsonify }},
3
- "cloudcannon": {
4
- "name": "cloudcannon-jekyll",
5
- "version": {{ gem_version | cc_jsonify }}
6
- },
7
- {% if config.timezone %}"timezone": {{ config.timezone | cc_jsonify }},{% endif %}
8
- "include": {{ config.include | cc_jsonify }},
9
- "exclude": {{ config.exclude | cc_jsonify }},
10
- {% if config.baseurl %}"base-url": {{ config.baseurl | cc_jsonify }},{% endif %}
11
- "collections": {{ collections | cc_jsonify: 'collections' }},
12
- {% if config._comments %}"comments": {{ config._comments | cc_jsonify }},{% endif %}
13
- {% if config._options %}"input-options": {{ config._options | cc_jsonify }},{% endif %}
14
- {% if config.defaults %}"defaults": {{ config.defaults | cc_jsonify }},{% endif %}
15
- {% if config._editor %}"editor": {
16
- "default-path": {{ config._editor.default_path | cc_jsonify }}
17
- },{% endif %}
18
- {% if config._source_editor %}"source-editor": {
19
- "tab-size": {{ config._source_editor.tab_size | cc_jsonify }},
20
- "show-gutter": {{ config._source_editor.show_gutter | cc_jsonify }},
21
- "theme": {{ config._source_editor.theme | cc_jsonify }}
22
- },{% endif %}
23
- {% if config._explore %}"explore": {{ config._explore | cc_jsonify }},{% endif %}
24
- "paths": {
25
- "uploads": {{ config.uploads_dir | cc_jsonify }},
26
- "plugins": {{ config.plugins_dir | cc_jsonify }},
27
- "data": {{ config.data_dir | cc_jsonify }},
28
- "pages": "",
29
- "collections": {{ config.collections_dir | cc_jsonify }},
30
- "includes": {{ config.includes_dir | cc_jsonify }},
31
- "layouts": {{ config.layouts_dir | cc_jsonify }}
32
- },
33
- {% if config._array_structures %}"array-structures": {{ config._array_structures | cc_jsonify: nil, 20 }},{% endif %}
34
- {% assign select_data = config | cc_select_data_jsonify %}{% if select_data %}"select-data": {{ select_data }},{% endif %}
35
- "source": {{ config.source | replace: pwd, "" | cc_jsonify }}
36
- }
@@ -1,36 +0,0 @@
1
- {
2
- "time": {{ site.time | date_to_xmlschema | cc_jsonify }},
3
- "cloudcannon": {
4
- "name": "cloudcannon-jekyll",
5
- "version": {{ gem_version | cc_jsonify }}
6
- },
7
- {% if config.timezone %}"timezone": {{ config.timezone | cc_jsonify }},{% endif %}
8
- "include": {{ config.include | cc_jsonify }},
9
- "exclude": {{ config.exclude | cc_jsonify }},
10
- {% if config.baseurl %}"base-url": {{ config.baseurl | cc_jsonify }},{% endif %}
11
- "collections": {{ collections | cc_jsonify: 'collections' }},
12
- {% if config._comments %}"comments": {{ config._comments | cc_jsonify }},{% endif %}
13
- {% if config._options %}"input-options": {{ config._options | cc_jsonify }},{% endif %}
14
- {% if config.defaults %}"defaults": {{ config.defaults | cc_jsonify }},{% endif %}
15
- {% if config._editor %}"editor": {
16
- "default-path": {{ config._editor.default_path | cc_jsonify }}
17
- },{% endif %}
18
- {% if config._source_editor %}"source-editor": {
19
- "tab-size": {{ config._source_editor.tab_size | cc_jsonify }},
20
- "show-gutter": {{ config._source_editor.show_gutter | cc_jsonify }},
21
- "theme": {{ config._source_editor.theme | cc_jsonify }}
22
- },{% endif %}
23
- {% if config._explore %}"explore": {{ config._explore | cc_jsonify }},{% endif %}
24
- "paths": {
25
- "uploads": {{ config.uploads_dir | cc_jsonify }},
26
- "plugins": {{ config.plugins_dir | cc_jsonify }},
27
- "data": {{ config.data_dir | cc_jsonify }},
28
- "pages": "",
29
- "collections": {{ config.collections_dir | cc_jsonify }},
30
- "includes": {{ config.includes_dir | cc_jsonify }},
31
- "layouts": {{ config.layouts_dir | cc_jsonify }}
32
- },
33
- {% if config._array_structures %}"array-structures": {{ config._array_structures | cc_jsonify: nil, 20 }},{% endif %}
34
- {% assign select_data = config | cc_select_data_jsonify %}{% if select_data %}"select-data": {{ select_data }},{% endif %}
35
- "source": {{ config.source | replace: pwd, "" | cc_jsonify }}
36
- }
@@ -1,57 +0,0 @@
1
- {
2
- "time": {{ site.time | date_to_xmlschema | cc_jsonify }},
3
- "cloudcannon": {
4
- "name": "cloudcannon-jekyll",
5
- "version": {{ gem_version | cc_jsonify }}
6
- },
7
- {% if config.timezone -%}
8
- "timezone": {{ config.timezone | cc_jsonify }},
9
- {%- endif %}
10
- "include": {{ config.include | cc_jsonify }},
11
- "exclude": {{ config.exclude | cc_jsonify }},
12
- {% if config.baseurl -%}
13
- "base-url": {{ config.baseurl | cc_jsonify }},
14
- {%- endif %}
15
- "collections": {{ collections | cc_jsonify: 'collections' }},
16
- {% if config._comments -%}
17
- "comments": {{ config._comments | cc_jsonify }},
18
- {%- endif %}
19
- {% if config._options -%}
20
- "input-options": {{ config._options | cc_jsonify }},
21
- {%- endif %}
22
- {% if config.defaults -%}
23
- "defaults": {{ config.defaults | cc_jsonify }},
24
- {%- endif %}
25
- {% if config._editor -%}
26
- "editor": {
27
- "default-path": {{ config._editor.default_path | cc_jsonify }}
28
- },
29
- {%- endif %}
30
- {% if config._source_editor -%}
31
- "source-editor": {
32
- "tab-size": {{ config._source_editor.tab_size | cc_jsonify }},
33
- "show-gutter": {{ config._source_editor.show_gutter | cc_jsonify }},
34
- "theme": {{ config._source_editor.theme | cc_jsonify }}
35
- },
36
- {%- endif %}
37
- {% if config._explore -%}
38
- "explore": {{ config._explore | cc_jsonify }},
39
- {%- endif %}
40
- "paths": {
41
- "uploads": {{ config.uploads_dir | cc_jsonify }},
42
- "plugins": {{ config.plugins_dir | cc_jsonify }},
43
- "data": {{ config.data_dir | cc_jsonify }},
44
- "pages": "",
45
- "collections": {{ config.collections_dir | cc_jsonify }},
46
- "includes": {{ config.includes_dir | cc_jsonify }},
47
- "layouts": {{ config.layouts_dir | cc_jsonify }}
48
- },
49
- {% if config._array_structures -%}
50
- "array-structures": {{ config._array_structures | cc_jsonify: nil, 20 }},
51
- {%- endif %}
52
- {% assign select_data = config | cc_select_data_jsonify -%}
53
- {% if select_data -%}
54
- "select-data": {{ select_data }},
55
- {%- endif %}
56
- "source": {{ config.source | replace: pwd, "" | cc_jsonify }}
57
- }
@@ -1,28 +0,0 @@
1
- {
2
- "time": {{ site.time | date_to_xmlschema | cc_jsonify }},
3
- "cloudcannon": {
4
- "name": "cloudcannon-jekyll",
5
- "version": {{ gem_version | cc_jsonify }}
6
- },
7
- "generator": {
8
- "name": "jekyll",
9
- "version": {{ jekyll.version | cc_jsonify }},
10
- "environment": {{ jekyll.env | cc_jsonify }},
11
- "metadata": {
12
- "markdown": {{ site.markdown | cc_jsonify }},
13
- "kramdown": {{ site.kramdown | cc_jsonify }},
14
- "commonmark": {{ site.commonmark | cc_jsonify }}
15
- }
16
- },{% if site.cloudcannon.data.first %}{% assign data_seen = false %}
17
- "data": {
18
- {% 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 %}},
19
- {% elsif site.cloudcannon.data %}"data": {{ site.data | cc_jsonify }},{% endif %}
20
- "collections": {
21
- "drafts": {{ drafts | cc_jsonify }},
22
- "posts": {{ site.posts | reverse | cc_jsonify }}{% if site.collections.size > 0 %},{% endif %}
23
- {% for collection in site.collections %}"{{ collection[0] | xml_escape }}": {{ collection[1].docs | cc_jsonify }}{% unless forloop.last %},{% endunless %}
24
- {% endfor %}
25
- },
26
- "pages": {{ site.pages | cc_jsonify }},
27
- "static-pages": {{ site.static_files | cc_static_files_jsonify }}
28
- }
@@ -1,27 +0,0 @@
1
- {
2
- "time": {{ site.time | date_to_xmlschema | cc_jsonify }},
3
- "cloudcannon": {
4
- "name": "cloudcannon-jekyll",
5
- "version": {{ gem_version | cc_jsonify }}
6
- },
7
- "generator": {
8
- "name": "jekyll",
9
- "version": {{ jekyll.version | cc_jsonify }},
10
- "environment": {{ jekyll.env | cc_jsonify }},
11
- "metadata": {
12
- "markdown": {{ site.markdown | cc_jsonify }},
13
- "kramdown": {{ site.kramdown | cc_jsonify }},
14
- "commonmark": {{ site.commonmark | cc_jsonify }}
15
- }
16
- },{% if site.cloudcannon.data.first %}{% assign data_seen = false %}
17
- "data": {
18
- {% 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 %}},
19
- {% elsif site.cloudcannon.data %}"data": {{ site.data | cc_jsonify }},{% endif %}
20
- "collections": {
21
- "drafts": {{ drafts | cc_jsonify }}{% if site.collections.size > 0 %},{% endif %}
22
- {% for collection in site.collections %}"{{ collection.label | xml_escape }}": {{ collection.docs | cc_jsonify }}{% unless forloop.last %},{% endunless %}
23
- {% endfor %}
24
- },
25
- "pages": {{ site.pages | cc_jsonify }},
26
- "static-pages": {{ site.static_files | cc_static_files_jsonify }}
27
- }
@@ -1,41 +0,0 @@
1
- {
2
- "time": {{ site.time | date_to_xmlschema | cc_jsonify }},
3
- "cloudcannon": {
4
- "name": "cloudcannon-jekyll",
5
- "version": {{ gem_version | cc_jsonify }}
6
- },
7
- "generator": {
8
- "name": "jekyll",
9
- "version": {{ jekyll.version | cc_jsonify }},
10
- "environment": {{ jekyll.env | cc_jsonify }},
11
- "metadata": {
12
- "markdown": {{ site.markdown | cc_jsonify }},
13
- "kramdown": {{ site.kramdown | cc_jsonify }},
14
- "commonmark": {{ site.commonmark | cc_jsonify }}
15
- }
16
- },
17
- {% if site.cloudcannon.data.first -%}
18
- "data": {
19
- {%- assign data_seen = false %}
20
- {%- for data in site.data %}
21
- {%- assign key = data[0] %}
22
- {%- if site.cloudcannon.data[key] %}
23
- {%- if data_seen %},{% endif -%}
24
- {{ data[0] | cc_jsonify }}: {{ data[1] | cc_jsonify }}
25
- {%- assign data_seen = true %}
26
- {%- endif %}
27
- {%- endfor -%}
28
- },
29
- {% elsif site.cloudcannon.data -%}
30
- "data": {{ site.data | cc_jsonify }},
31
- {%- endif %}
32
- "collections": {
33
- "drafts": {{ drafts | cc_jsonify }}{% if site.collections.size > 0 %},{% endif %}
34
- {%- for collection in site.collections -%}
35
- "{{ collection.label | xml_escape }}": {{ collection.docs | cc_jsonify }}
36
- {%- unless forloop.last %},{% endunless %}
37
- {%- endfor -%}
38
- },
39
- "pages": {{ site.pages | cc_jsonify }},
40
- "static-pages": {{ site.static_files | cc_static_files_jsonify }}
41
- }