cloudcannon-jekyll 0.1.0 → 0.3.2
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/.github/workflows/stale.yml +19 -0
- data/.reek.yml +6 -0
- data/.rubocop.yml +24 -2
- data/.travis.yml +2 -1
- data/Gemfile +2 -0
- data/HISTORY.md +43 -0
- data/cloudcannon-jekyll.gemspec +3 -3
- data/lib/cloudcannon-jekyll.rb +4 -4
- data/lib/cloudcannon-jekyll/_cloudcannon/config-2.x.json +29 -36
- data/lib/cloudcannon-jekyll/_cloudcannon/config-3.0-4.x.json +29 -36
- data/lib/cloudcannon-jekyll/_cloudcannon/config.json +40 -44
- data/lib/cloudcannon-jekyll/_cloudcannon/details-2.x.json +14 -13
- data/lib/cloudcannon-jekyll/_cloudcannon/details-3.0-4.x.json +13 -12
- data/lib/cloudcannon-jekyll/_cloudcannon/details.json +13 -12
- data/lib/cloudcannon-jekyll/configuration.rb +2 -1
- data/lib/cloudcannon-jekyll/generator.rb +115 -15
- data/lib/cloudcannon-jekyll/jsonify-filter.rb +218 -0
- data/lib/cloudcannon-jekyll/page-without-a-file.rb +1 -0
- data/lib/cloudcannon-jekyll/reader.rb +38 -0
- data/lib/cloudcannon-jekyll/readers/data-reader.rb +18 -0
- data/lib/cloudcannon-jekyll/readers/old-data-reader.rb +55 -0
- data/lib/cloudcannon-jekyll/version.rb +1 -1
- data/script/ci-smoke-test +10 -0
- data/script/cibuild +1 -2
- data/script/test +1 -0
- metadata +27 -22
- data/lib/cloudcannon-jekyll/safe-jsonify-filter.rb +0 -210
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "jekyll"
|
4
|
+
|
5
|
+
begin
|
6
|
+
require_relative "readers/data-reader"
|
7
|
+
rescue NameError
|
8
|
+
require_relative "readers/old-data-reader"
|
9
|
+
end
|
10
|
+
|
11
|
+
module CloudCannonJekyll
|
12
|
+
# Wraps read functions into one class
|
13
|
+
class Reader
|
14
|
+
attr_reader :site
|
15
|
+
|
16
|
+
def initialize(site)
|
17
|
+
@site = site
|
18
|
+
end
|
19
|
+
|
20
|
+
def read_data(dir = "_data")
|
21
|
+
CloudCannonJekyll::DataReader.new(@site).read(dir)
|
22
|
+
rescue NameError # DataReader doesn't exist in old versions of Jekyll
|
23
|
+
CloudCannonJekyll::OldDataReader.new(@site).read(dir)
|
24
|
+
end
|
25
|
+
|
26
|
+
def read_drafts(dir = "")
|
27
|
+
Jekyll::PostReader.new(@site).read_drafts(dir)
|
28
|
+
rescue NameError # PostReader doesn't exist in old versions of Jekyll
|
29
|
+
@site.read_content(dir, "_drafts", Jekyll::Draft)
|
30
|
+
end
|
31
|
+
|
32
|
+
def read_posts(dir = "")
|
33
|
+
Jekyll::PostReader.new(@site).read_posts(dir)
|
34
|
+
rescue NameError # PostReader doesn't exist in old versions of Jekyll
|
35
|
+
@site.read_content(dir, "_posts", Jekyll::Post)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "jekyll"
|
4
|
+
|
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
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
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
|
16
|
+
|
17
|
+
def read(dir)
|
18
|
+
base = Jekyll.sanitized_path(@site.source, dir)
|
19
|
+
read_data_to(base, @content)
|
20
|
+
@content
|
21
|
+
end
|
22
|
+
|
23
|
+
def read_data_to(dir, data)
|
24
|
+
return unless File.directory?(dir) && (!@safe || !File.symlink?(dir))
|
25
|
+
|
26
|
+
entries = Dir.chdir(dir) do
|
27
|
+
Dir["*.{yaml,yml,json,csv}"] + Dir["*"].select { |fn| File.directory?(fn) }
|
28
|
+
end
|
29
|
+
|
30
|
+
entries.each do |entry|
|
31
|
+
path = Jekyll.sanitized_path(dir, entry)
|
32
|
+
next if File.symlink?(path) && @safe
|
33
|
+
|
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)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def read_data_file(path)
|
44
|
+
{
|
45
|
+
"path" => path,
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
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+!, "_")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
set -ex
|
4
|
+
|
5
|
+
# Checks to see the build is likely to fail on Travis.
|
6
|
+
# Duplicated the versions from .travis.yml
|
7
|
+
|
8
|
+
JEKYLL_VERSION=2.4.0 bundle update && $(dirname "$0")/test &&
|
9
|
+
JEKYLL_VERSION=3.0.0 bundle update && $(dirname "$0")/test &&
|
10
|
+
JEKYLL_VERSION=3.2.1 bundle update && $(dirname "$0")/test
|
data/script/cibuild
CHANGED
data/script/test
CHANGED
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.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CloudCannon
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -30,6 +30,20 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '4'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: json_schemer
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.2.4
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.2.4
|
33
47
|
- !ruby/object:Gem::Dependency
|
34
48
|
name: rake
|
35
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,20 +100,6 @@ dependencies:
|
|
86
100
|
- - "~>"
|
87
101
|
- !ruby/object:Gem::Version
|
88
102
|
version: '0.11'
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
|
-
name: json_schemer
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - "~>"
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: 0.2.13
|
96
|
-
type: :development
|
97
|
-
prerelease: false
|
98
|
-
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - "~>"
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: 0.2.13
|
103
103
|
description: Creates CloudCannon editor details for Jekyll
|
104
104
|
email:
|
105
105
|
- support@cloudcannon.com
|
@@ -107,7 +107,9 @@ executables: []
|
|
107
107
|
extensions: []
|
108
108
|
extra_rdoc_files: []
|
109
109
|
files:
|
110
|
+
- ".github/workflows/stale.yml"
|
110
111
|
- ".gitignore"
|
112
|
+
- ".reek.yml"
|
111
113
|
- ".rspec"
|
112
114
|
- ".rubocop.yml"
|
113
115
|
- ".travis.yml"
|
@@ -126,9 +128,13 @@ files:
|
|
126
128
|
- lib/cloudcannon-jekyll/_cloudcannon/details.json
|
127
129
|
- lib/cloudcannon-jekyll/configuration.rb
|
128
130
|
- lib/cloudcannon-jekyll/generator.rb
|
131
|
+
- lib/cloudcannon-jekyll/jsonify-filter.rb
|
129
132
|
- lib/cloudcannon-jekyll/page-without-a-file.rb
|
130
|
-
- lib/cloudcannon-jekyll/
|
133
|
+
- lib/cloudcannon-jekyll/reader.rb
|
134
|
+
- lib/cloudcannon-jekyll/readers/data-reader.rb
|
135
|
+
- lib/cloudcannon-jekyll/readers/old-data-reader.rb
|
131
136
|
- lib/cloudcannon-jekyll/version.rb
|
137
|
+
- script/ci-smoke-test
|
132
138
|
- script/cibuild
|
133
139
|
- script/release
|
134
140
|
- script/test
|
@@ -136,7 +142,7 @@ homepage: https://github.com/cloudcannon/cloudcannon-jekyll
|
|
136
142
|
licenses:
|
137
143
|
- MIT
|
138
144
|
metadata: {}
|
139
|
-
post_install_message:
|
145
|
+
post_install_message:
|
140
146
|
rdoc_options: []
|
141
147
|
require_paths:
|
142
148
|
- lib
|
@@ -151,9 +157,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
157
|
- !ruby/object:Gem::Version
|
152
158
|
version: '0'
|
153
159
|
requirements: []
|
154
|
-
|
155
|
-
|
156
|
-
signing_key:
|
160
|
+
rubygems_version: 3.0.3
|
161
|
+
signing_key:
|
157
162
|
specification_version: 4
|
158
163
|
summary: CloudCannon Jekyll integration
|
159
164
|
test_files: []
|
@@ -1,210 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "jekyll"
|
4
|
-
|
5
|
-
module CloudCannonJekyll
|
6
|
-
module SafeJsonifyFilter
|
7
|
-
@simple_types = [
|
8
|
-
String,
|
9
|
-
Numeric,
|
10
|
-
Integer,
|
11
|
-
Float,
|
12
|
-
Date,
|
13
|
-
Time,
|
14
|
-
NilClass,
|
15
|
-
Object.const_defined?("Fixnum") ? Fixnum : nil,
|
16
|
-
].compact.freeze
|
17
|
-
|
18
|
-
@document_types = [
|
19
|
-
Jekyll::Document,
|
20
|
-
Jekyll::Page,
|
21
|
-
Jekyll::VERSION.start_with?("2.") ? Jekyll::Post : nil,
|
22
|
-
].compact.freeze
|
23
|
-
|
24
|
-
def self.document_type?(input)
|
25
|
-
@document_types.include?(input.class)
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.simple_type?(input)
|
29
|
-
@simple_types.include?(input.class) || [true, false].include?(input)
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.static_file_to_json(input, depth)
|
33
|
-
out = [
|
34
|
-
"\"extname\": #{SafeJsonifyFilter.to_json(input.extname, depth + 1)}",
|
35
|
-
"\"path\": #{SafeJsonifyFilter.to_json(input.relative_path, depth + 1)}",
|
36
|
-
]
|
37
|
-
|
38
|
-
# modified_time isn't defined in Jekyll 2.4.0
|
39
|
-
if input.respond_to? :modified_time
|
40
|
-
out.push("\"modified_time\": #{SafeJsonifyFilter.to_json(input.modified_time, depth + 1)}")
|
41
|
-
end
|
42
|
-
|
43
|
-
"{#{out.join(",")}}"
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.document_data_to_json(data, out, prevent, depth)
|
47
|
-
prevent += %w(content output next previous excerpt)
|
48
|
-
|
49
|
-
data.each { |key, value|
|
50
|
-
next if prevent.include? key
|
51
|
-
prevent.push key
|
52
|
-
out.push("#{key.to_json}: #{SafeJsonifyFilter.to_json(value, depth + 1)}")
|
53
|
-
}
|
54
|
-
|
55
|
-
"{#{out.join(",")}}"
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.legacy_post_to_json(input, depth)
|
59
|
-
prevent = %w(dir name path url date id categories tags)
|
60
|
-
|
61
|
-
out = [
|
62
|
-
"\"dir\": #{SafeJsonifyFilter.to_json(input.dir, depth + 1)}",
|
63
|
-
"\"name\": #{SafeJsonifyFilter.to_json(input.name, depth + 1)}",
|
64
|
-
"\"path\": #{SafeJsonifyFilter.to_json(input.path, depth + 1)}",
|
65
|
-
"\"url\": #{SafeJsonifyFilter.to_json(input.url, depth + 1)}",
|
66
|
-
"\"date\": #{SafeJsonifyFilter.to_json(input.date, depth + 1)}",
|
67
|
-
"\"id\": #{SafeJsonifyFilter.to_json(input.id, depth + 1)}",
|
68
|
-
"\"categories\": #{SafeJsonifyFilter.to_json(input.categories, depth + 1)}",
|
69
|
-
"\"tags\": #{SafeJsonifyFilter.to_json(input.tags, depth + 1)}",
|
70
|
-
]
|
71
|
-
|
72
|
-
SafeJsonifyFilter.document_data_to_json(input.data, out, prevent, depth)
|
73
|
-
end
|
74
|
-
|
75
|
-
def self.page_to_json(input, depth)
|
76
|
-
prevent = %w(dir name path url)
|
77
|
-
|
78
|
-
out = [
|
79
|
-
"\"dir\": #{SafeJsonifyFilter.to_json(input.dir, depth + 1)}",
|
80
|
-
"\"name\": #{SafeJsonifyFilter.to_json(input.name, depth + 1)}",
|
81
|
-
"\"path\": #{SafeJsonifyFilter.to_json(input.path, depth + 1)}",
|
82
|
-
"\"url\": #{SafeJsonifyFilter.to_json(input.url, depth + 1)}",
|
83
|
-
]
|
84
|
-
|
85
|
-
# Merge Jekyll Defaults into data for pages (missing at v3.8.5)
|
86
|
-
defaults = input.site.frontmatter_defaults.all(input.relative_path, :pages).tap do |h|
|
87
|
-
h.delete("date")
|
88
|
-
end
|
89
|
-
|
90
|
-
data = Jekyll::Utils.deep_merge_hashes(defaults, input.data)
|
91
|
-
SafeJsonifyFilter.document_data_to_json(data, out, prevent, depth)
|
92
|
-
end
|
93
|
-
|
94
|
-
def self.document_to_json(input, depth)
|
95
|
-
prevent = %w(dir id relative_path url collection)
|
96
|
-
|
97
|
-
out = [
|
98
|
-
"\"path\": #{SafeJsonifyFilter.to_json(input.relative_path, depth + 1)}",
|
99
|
-
"\"relative_path\": #{SafeJsonifyFilter.to_json(input.relative_path, depth + 1)}",
|
100
|
-
"\"url\": #{SafeJsonifyFilter.to_json(input.url, depth + 1)}",
|
101
|
-
]
|
102
|
-
|
103
|
-
unless input.collection.nil?
|
104
|
-
out.push("\"collection\": #{SafeJsonifyFilter.to_json(input.collection.label, depth + 1)}")
|
105
|
-
end
|
106
|
-
|
107
|
-
# id isn't defined in Jekyll 2.4.0
|
108
|
-
out.push("\"id\": #{SafeJsonifyFilter.to_json(input.id, depth + 1)}") if input.respond_to? :id
|
109
|
-
|
110
|
-
SafeJsonifyFilter.document_data_to_json(input.data, out, prevent, depth)
|
111
|
-
end
|
112
|
-
|
113
|
-
def self.array_to_json(input, depth)
|
114
|
-
array = input.map do |value|
|
115
|
-
SafeJsonifyFilter.to_json(value, depth + 1)
|
116
|
-
end
|
117
|
-
|
118
|
-
"[#{array.join(",")}]"
|
119
|
-
end
|
120
|
-
|
121
|
-
def self.hash_to_json(input, depth)
|
122
|
-
hash = input.map do |key, value|
|
123
|
-
"#{key.to_json}: #{SafeJsonifyFilter.to_json(value, depth + 1)}"
|
124
|
-
end
|
125
|
-
|
126
|
-
"{#{hash.join(",")}}"
|
127
|
-
end
|
128
|
-
|
129
|
-
def self.site_drop_legacy_select_data_to_json(input, depth)
|
130
|
-
prevent = %w(config time related_posts destination cache_dir safe
|
131
|
-
keep_files encoding markdown_ext strict_front_matter show_drafts
|
132
|
-
limit_posts future unpublished whitelist maruku markdown highlighter
|
133
|
-
lsi excerpt_separator incremental detach port host show_dir_listing
|
134
|
-
permalink paginate_path quiet verbose defaults liquid kramdown title
|
135
|
-
url description categories data tags static_files html_pages pages
|
136
|
-
documents posts related_posts time source timezone include exclude
|
137
|
-
baseurl collections _comments _editor _source_editor _explore
|
138
|
-
uploads_dir plugins_dir data_dir collections_dir includes_dir
|
139
|
-
layouts_dir _array_structures cloudcannon rdiscount redcarpet redcloth)
|
140
|
-
|
141
|
-
if Jekyll::VERSION.start_with?("2.")
|
142
|
-
prevent = prevent.concat input["collections"].keys
|
143
|
-
prevent.push "gems"
|
144
|
-
elsif Jekyll::VERSION.match?(%r!3\.[0-4]\.!)
|
145
|
-
prevent = prevent.concat input["collections"].map { |c| c["label"] }
|
146
|
-
prevent = prevent.concat %w(plugins gems)
|
147
|
-
else
|
148
|
-
prevent.push "plugins"
|
149
|
-
end
|
150
|
-
|
151
|
-
out = input.map { |key, value|
|
152
|
-
next unless value.is_a?(Array) || value.is_a?(Hash)
|
153
|
-
next if prevent.include? key
|
154
|
-
prevent.push key
|
155
|
-
|
156
|
-
"#{key.to_json}: #{SafeJsonifyFilter.to_json(value, depth + 1)}"
|
157
|
-
}.compact
|
158
|
-
|
159
|
-
"{#{out.join(",")}}" if out.any?
|
160
|
-
end
|
161
|
-
|
162
|
-
def self.to_json(input, depth)
|
163
|
-
if depth > 8 || (depth > 2 && SafeJsonifyFilter.document_type?(input))
|
164
|
-
'"MAXIMUM_DEPTH"'
|
165
|
-
elsif SafeJsonifyFilter.simple_type?(input)
|
166
|
-
input.to_json
|
167
|
-
elsif input.is_a?(Jekyll::StaticFile)
|
168
|
-
SafeJsonifyFilter.static_file_to_json(input, depth)
|
169
|
-
elsif input.is_a?(Jekyll::Page)
|
170
|
-
SafeJsonifyFilter.page_to_json(input, depth)
|
171
|
-
elsif Jekyll::VERSION.start_with?("2.") && input.is_a?(Jekyll::Post)
|
172
|
-
SafeJsonifyFilter.legacy_post_to_json(input, depth)
|
173
|
-
elsif input.is_a?(Jekyll::Document)
|
174
|
-
SafeJsonifyFilter.document_to_json(input, depth)
|
175
|
-
elsif input.is_a?(Array)
|
176
|
-
SafeJsonifyFilter.array_to_json(input, depth)
|
177
|
-
elsif input.is_a?(Hash)
|
178
|
-
SafeJsonifyFilter.hash_to_json(input, depth)
|
179
|
-
else
|
180
|
-
"\"UNSUPPORTED:#{input.class.to_json}\""
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
def cc_static_files_jsonify(input)
|
185
|
-
out = []
|
186
|
-
input.each do |page|
|
187
|
-
next if page.extname != ".html" &&
|
188
|
-
page.extname != ".htm" &&
|
189
|
-
page.path != "/robots.txt" &&
|
190
|
-
page.path != "/sitemap.xml"
|
191
|
-
|
192
|
-
out.push(SafeJsonifyFilter.to_json(page, 1))
|
193
|
-
end
|
194
|
-
|
195
|
-
"[#{out.join(",")}]"
|
196
|
-
end
|
197
|
-
|
198
|
-
def cc_site_select_data_jsonify(input)
|
199
|
-
if input.key? "_select_data"
|
200
|
-
SafeJsonifyFilter.to_json(input["_select_data"], 0)
|
201
|
-
else
|
202
|
-
SafeJsonifyFilter.site_drop_legacy_select_data_to_json(input, 0)
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
def cc_safe_jsonify(input)
|
207
|
-
SafeJsonifyFilter.to_json(input, 0)
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|