cloudcannon-jekyll 0.3.0 → 0.4.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 +4 -4
- data/.gitignore +2 -2
- data/HISTORY.md +27 -1
- data/lib/cloudcannon-jekyll/_cloudcannon/details-2.x.json +1 -1
- data/lib/cloudcannon-jekyll/_cloudcannon/details-3.0-4.x.json +1 -1
- data/lib/cloudcannon-jekyll/_cloudcannon/details.json +1 -1
- data/lib/cloudcannon-jekyll/generator.rb +15 -5
- data/lib/cloudcannon-jekyll/jsonify-filter.rb +18 -6
- data/lib/cloudcannon-jekyll/reader.rb +5 -6
- data/lib/cloudcannon-jekyll/readers/data-reader.rb +14 -12
- data/lib/cloudcannon-jekyll/readers/old-data-reader.rb +43 -41
- data/lib/cloudcannon-jekyll/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fb6d69020a149aa142d3e07d56e684c228a66f6b85af4f90ea3b2ec781960a7
|
4
|
+
data.tar.gz: 8ab26b830892091e808583431104d5196b606aae6e5f03eb65a85025a4dc93ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9569e09b712f5ce8902da2b09ec22ceb7472690a497a03a22187801dc4574425722b5370b49177c4313d466dac8edb57a7624f1e7ca8d5273fc48aee9cd37261
|
7
|
+
data.tar.gz: 59cd301082e6169baf3a96df82f0fe7cfc9857475dbc50925e64ad6e5d4ca93aef28961e1bef0766946cf3e1db4cb71c1fee35dc6bcca5de4240498b56736a1f
|
data/.gitignore
CHANGED
data/HISTORY.md
CHANGED
@@ -1,5 +1,32 @@
|
|
1
|
+
# 0.4.0
|
2
|
+
|
3
|
+
* Add `collections_dir` to details collection item paths
|
4
|
+
* Fix pages collection clash with built-in pages
|
5
|
+
* Fixed posts collection config data overwriting drafts data
|
6
|
+
* Force generator to run after other lowest priority plugins
|
7
|
+
|
8
|
+
# 0.3.4
|
9
|
+
|
10
|
+
* Re-add id field for documents
|
11
|
+
* Fix for potential nil reference
|
12
|
+
|
13
|
+
# 0.3.3
|
14
|
+
|
15
|
+
* Rework fallback for older versions of Jekyll when reading data, posts and drafts again
|
16
|
+
|
17
|
+
# 0.3.2
|
18
|
+
|
19
|
+
* Rework fallback for older versions of Jekyll when reading data, posts and drafts
|
20
|
+
* Fix deprecation warning for `posts.map`
|
21
|
+
|
22
|
+
# 0.3.1
|
23
|
+
|
24
|
+
* Fix for empty collection configurations
|
25
|
+
* Added max depth parameter for jsonify filter and increase it for array structures in config output
|
26
|
+
|
1
27
|
# 0.3.0
|
2
28
|
|
29
|
+
* Add empty paths.pages
|
3
30
|
* Added drafts to collections in details
|
4
31
|
* Added drafts and data to collections in config
|
5
32
|
* Added category folder drafts and posts to collections in config
|
@@ -8,7 +35,6 @@
|
|
8
35
|
* Renamed static to static-pages in details and removed `robots.txt` and `sitemap.xml` exceptions
|
9
36
|
* Add `url` to static-pages
|
10
37
|
* Normalise `_path` in static-pages
|
11
|
-
* Added max depth parameter for jsonify filter and increase it for array structures in config output
|
12
38
|
|
13
39
|
# 0.2.2
|
14
40
|
|
@@ -23,6 +23,6 @@
|
|
23
23
|
{% for collection in site.collections %}"{{ collection[0] | xml_escape }}": {{ collection[1].docs | cc_jsonify }}{% unless forloop.last %},{% endunless %}
|
24
24
|
{% endfor %}
|
25
25
|
},
|
26
|
-
"pages": {{ site.
|
26
|
+
"pages": {{ site.html_pages | cc_jsonify }},
|
27
27
|
"static-pages": {{ site.static_files | cc_static_files_jsonify }}
|
28
28
|
}
|
@@ -22,6 +22,6 @@
|
|
22
22
|
{% for collection in site.collections %}"{{ collection.label | xml_escape }}": {{ collection.docs | cc_jsonify }}{% unless forloop.last %},{% endunless %}
|
23
23
|
{% endfor %}
|
24
24
|
},
|
25
|
-
"pages": {{ site.
|
25
|
+
"pages": {{ site.html_pages | cc_jsonify }},
|
26
26
|
"static-pages": {{ site.static_files | cc_static_files_jsonify }}
|
27
27
|
}
|
@@ -7,13 +7,22 @@ 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"]
|
20
|
+
collections_config = @site.config["collections"]&.dup || {}
|
21
|
+
|
22
|
+
# Workaround for empty collection configurations
|
23
|
+
collections_config.each_key do |key|
|
24
|
+
collections_config[key] ||= { "output" => false }
|
25
|
+
end
|
17
26
|
|
18
27
|
payload = @site.site_payload.merge({
|
19
28
|
"gem_version" => CloudCannonJekyll::VERSION,
|
@@ -44,11 +53,13 @@ module CloudCannonJekyll
|
|
44
53
|
@site.config["data_dir"] || "_data"
|
45
54
|
end
|
46
55
|
|
56
|
+
# rubocop:disable Metrics/AbcSize
|
47
57
|
def add_category_folder_config(collections_config, posts_config = {})
|
48
58
|
posts = @site.posts || @site.collections["posts"]
|
59
|
+
docs = posts.class.method_defined?(:docs) ? posts.docs : posts
|
49
60
|
seen = {}
|
50
61
|
|
51
|
-
|
62
|
+
docs.map do |post|
|
52
63
|
parts = post.relative_path.split("/_posts/")
|
53
64
|
path = parts.first
|
54
65
|
|
@@ -75,6 +86,7 @@ module CloudCannonJekyll
|
|
75
86
|
path
|
76
87
|
end
|
77
88
|
end
|
89
|
+
# rubocop:enable Metrics/AbcSize
|
78
90
|
|
79
91
|
# Add data to collections config if raw data files exist
|
80
92
|
def add_data_config(collections_config)
|
@@ -87,9 +99,7 @@ module CloudCannonJekyll
|
|
87
99
|
collections_config["posts"] = { "output" => true } if Jekyll::VERSION.start_with? "2."
|
88
100
|
drafts = @reader.read_drafts(collections_dir)
|
89
101
|
|
90
|
-
if collections_config.key?("posts")
|
91
|
-
collections_config["drafts"] = collections_config["posts"].dup
|
92
|
-
elsif drafts.any?
|
102
|
+
if (collections_config.key?("posts") && !collections_config.key?("drafts")) || drafts.any?
|
93
103
|
collections_config["drafts"] = {}
|
94
104
|
end
|
95
105
|
|
@@ -107,20 +107,32 @@ module CloudCannonJekyll
|
|
107
107
|
"{#{out.join(",")}}"
|
108
108
|
end
|
109
109
|
|
110
|
+
def self.document_path(input)
|
111
|
+
collections_dir = input.site.config["collections_dir"] || ""
|
112
|
+
if input.collection && !collections_dir.empty?
|
113
|
+
"#{collections_dir}/#{input.relative_path}"
|
114
|
+
else
|
115
|
+
input.relative_path
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
110
119
|
def self.document_to_json(input, depth, max_depth)
|
111
|
-
prevent = %w(dir
|
120
|
+
prevent = %w(dir relative_path url collection)
|
112
121
|
|
113
122
|
out = [
|
114
|
-
"\"path\": #{JsonifyFilter.to_json(input
|
123
|
+
"\"path\": #{JsonifyFilter.to_json(JsonifyFilter.document_path(input), depth, max_depth)}",
|
115
124
|
"\"url\": #{JsonifyFilter.to_json(input.url, depth, max_depth)}",
|
116
125
|
]
|
117
126
|
|
118
|
-
|
119
|
-
|
120
|
-
collection_json = JsonifyFilter.to_json(collection.label, depth, max_depth)
|
127
|
+
unless input.collection.nil?
|
128
|
+
collection_json = JsonifyFilter.to_json(input.collection.label, depth, max_depth)
|
121
129
|
out.push("\"collection\": #{collection_json}")
|
122
130
|
end
|
123
131
|
|
132
|
+
if input.respond_to? :id
|
133
|
+
out.push("\"id\": #{JsonifyFilter.to_json(input.id, depth, max_depth)}")
|
134
|
+
end
|
135
|
+
|
124
136
|
out += JsonifyFilter.document_data_to_a(input.data, prevent, depth, max_depth)
|
125
137
|
"{#{out.join(",")}}"
|
126
138
|
end
|
@@ -168,7 +180,7 @@ module CloudCannonJekyll
|
|
168
180
|
def self.to_json(input, depth, max_depth = 9, key_swaps = {})
|
169
181
|
depth += 1
|
170
182
|
|
171
|
-
if depth > max_depth || (depth >
|
183
|
+
if depth > max_depth || (depth > 3 && JsonifyFilter.document_type?(input))
|
172
184
|
'"MAXIMUM_DEPTH"'
|
173
185
|
elsif JsonifyFilter.simple_type?(input)
|
174
186
|
input.to_json
|
@@ -1,12 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "jekyll"
|
4
|
-
|
5
|
-
|
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
|
-
|
3
|
+
unless Jekyll::VERSION.start_with? "2."
|
4
|
+
require "jekyll"
|
4
5
|
|
5
|
-
module CloudCannonJekyll
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
24
|
-
|
24
|
+
def read_data_to(dir, data)
|
25
|
+
return unless File.directory?(dir) && (!@safe || !File.symlink?(dir))
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
entries = Dir.chdir(dir) do
|
28
|
+
Dir["*.{yaml,yml,json,csv}"] + Dir["*"].select { |fn| File.directory?(fn) }
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
entries.each do |entry|
|
32
|
+
path = Jekyll.sanitized_path(dir, entry)
|
33
|
+
next if File.symlink?(path) && @safe
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
def read_data_file(path)
|
45
|
+
{
|
46
|
+
"path" => path,
|
47
|
+
}
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
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.
|
4
|
+
version: 0.4.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:
|
11
|
+
date: 2021-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -142,7 +142,7 @@ homepage: https://github.com/cloudcannon/cloudcannon-jekyll
|
|
142
142
|
licenses:
|
143
143
|
- MIT
|
144
144
|
metadata: {}
|
145
|
-
post_install_message:
|
145
|
+
post_install_message:
|
146
146
|
rdoc_options: []
|
147
147
|
require_paths:
|
148
148
|
- lib
|
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
158
|
version: '0'
|
159
159
|
requirements: []
|
160
160
|
rubygems_version: 3.0.3
|
161
|
-
signing_key:
|
161
|
+
signing_key:
|
162
162
|
specification_version: 4
|
163
163
|
summary: CloudCannon Jekyll integration
|
164
164
|
test_files: []
|