cloudcannon-jekyll 1.4.3 → 1.5.5
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/.rubocop.yml +1 -4
- data/HISTORY.md +33 -0
- data/lib/cloudcannon-jekyll.rb +1 -1
- data/lib/cloudcannon-jekyll/_cloudcannon/config-2.x.json +2 -1
- data/lib/cloudcannon-jekyll/_cloudcannon/config-3.0-4.x.json +2 -1
- data/lib/cloudcannon-jekyll/_cloudcannon/config.json +2 -3
- data/lib/cloudcannon-jekyll/_cloudcannon/details-2.x.json +2 -1
- data/lib/cloudcannon-jekyll/_cloudcannon/details-3.0-4.x.json +2 -1
- data/lib/cloudcannon-jekyll/_cloudcannon/details.json +2 -1
- data/lib/cloudcannon-jekyll/configuration.rb +1 -1
- data/lib/cloudcannon-jekyll/generator.rb +101 -6
- data/lib/cloudcannon-jekyll/jsonify-filter.rb +8 -19
- data/lib/cloudcannon-jekyll/reader.rb +43 -0
- data/lib/cloudcannon-jekyll/readers/data-reader.rb +20 -0
- data/lib/cloudcannon-jekyll/readers/old-data-reader.rb +57 -0
- data/lib/cloudcannon-jekyll/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 431460a2de8c6f3ec5dbfeb75e2354c48f25ac80f4761ef926dbee4fbdf10f63
|
4
|
+
data.tar.gz: 255202d3a0205cc9ee087d93ae2a96c59bbf662d3b335193cd6f2dedde6a917d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef6b43da5dc6bcdf08a8f8a7b711bb2b2a73cd28a48729c194eef89d7fbdc80bce2cf298f52fecb09695dbe25a0887f266f8e36887f8d888a29d41b8b6bfb23a
|
7
|
+
data.tar.gz: d456a64c940b19738d6588b9a69c05d69b3f13c143ffa849f028df78cde665152f723be143760cfa964244bc914950b3634099a62b2ca04a2293291d46523e64
|
@@ -0,0 +1,19 @@
|
|
1
|
+
name: Mark stale issues
|
2
|
+
|
3
|
+
on:
|
4
|
+
schedule:
|
5
|
+
- cron: "30 1 * * *"
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
stale:
|
9
|
+
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
|
12
|
+
steps:
|
13
|
+
- uses: actions/stale@v1
|
14
|
+
with:
|
15
|
+
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
16
|
+
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days'
|
17
|
+
stale-issue-label: 'no-issue-activity'
|
18
|
+
days-before-stale: 30
|
19
|
+
days-before-close: 5
|
data/.rubocop.yml
CHANGED
@@ -28,15 +28,12 @@ Naming/MemoizedInstanceVariableName:
|
|
28
28
|
Metrics/CyclomaticComplexity:
|
29
29
|
Exclude:
|
30
30
|
- lib/cloudcannon-jekyll/jsonify-filter.rb # TODO remove this and fix warnings
|
31
|
+
- lib/cloudcannon-jekyll/readers/old-data-reader.rb # TODO remove this and fix warnings
|
31
32
|
|
32
33
|
Metrics/PerceivedComplexity:
|
33
34
|
Exclude:
|
34
35
|
- lib/cloudcannon-jekyll/jsonify-filter.rb # TODO remove this and fix warnings
|
35
36
|
|
36
|
-
Metrics/MethodLength:
|
37
|
-
Exclude:
|
38
|
-
- lib/cloudcannon-jekyll/jsonify-filter.rb # TODO remove this and fix warnings
|
39
|
-
|
40
37
|
Metrics/AbcSize:
|
41
38
|
Exclude:
|
42
39
|
- lib/cloudcannon-jekyll/jsonify-filter.rb # TODO remove this and fix warnings
|
data/HISTORY.md
CHANGED
@@ -1,3 +1,36 @@
|
|
1
|
+
# 1.5.5
|
2
|
+
|
3
|
+
* Re-add id field for documents
|
4
|
+
* Fix for potential nil reference
|
5
|
+
|
6
|
+
# 1.5.4
|
7
|
+
|
8
|
+
* Rework fallback for older versions of Jekyll when reading data, posts and drafts again
|
9
|
+
|
10
|
+
# 1.5.3
|
11
|
+
|
12
|
+
* Rework fallback for older versions of Jekyll when reading data, posts and drafts
|
13
|
+
* Fix deprecation warning for `posts.map`
|
14
|
+
|
15
|
+
# 1.5.2
|
16
|
+
|
17
|
+
* Fix for empty collection configurations
|
18
|
+
|
19
|
+
# 1.5.1
|
20
|
+
|
21
|
+
* Add empty paths.pages
|
22
|
+
|
23
|
+
# 1.5.0
|
24
|
+
|
25
|
+
* Added drafts to collections in details
|
26
|
+
* Added drafts and data to collections in config
|
27
|
+
* Added category folder drafts and posts to collections in config
|
28
|
+
* Added `_path` field to each collection definition in config
|
29
|
+
* Removed some unused fields
|
30
|
+
* Renamed static to static-pages in details and removed `robots.txt` and `sitemap.xml` exceptions
|
31
|
+
* Add `url` to static-pages
|
32
|
+
* Normalise `_path` in static-pages
|
33
|
+
|
1
34
|
# 1.4.3
|
2
35
|
|
3
36
|
* Fix off-by-one depth for nested documents from last change
|
data/lib/cloudcannon-jekyll.rb
CHANGED
@@ -10,7 +10,7 @@ require_relative "cloudcannon-jekyll/version"
|
|
10
10
|
|
11
11
|
Liquid::Template.register_filter(CloudCannonJekyll::JsonifyFilter)
|
12
12
|
|
13
|
-
if Jekyll::VERSION.start_with? "2"
|
13
|
+
if Jekyll::VERSION.start_with? "2."
|
14
14
|
module Jekyll
|
15
15
|
# Hooks didn't exist in Jekyll 2 so we monkey patch to get an :after_reset hook
|
16
16
|
class Site
|
@@ -8,7 +8,7 @@
|
|
8
8
|
"include": {{ config.include | cc_jsonify }},
|
9
9
|
"exclude": {{ config.exclude | cc_jsonify }},
|
10
10
|
{% if config.baseurl %}"base-url": {{ config.baseurl | cc_jsonify }},{% endif %}
|
11
|
-
|
11
|
+
"collections": {{ collections | cc_jsonify: 'collections' }},
|
12
12
|
{% if config._comments %}"comments": {{ config._comments | cc_jsonify }},{% endif %}
|
13
13
|
{% if config._options %}"input-options": {{ config._options | cc_jsonify }},{% endif %}
|
14
14
|
{% if config.defaults %}"defaults": {{ config.defaults | cc_jsonify }},{% endif %}
|
@@ -25,6 +25,7 @@
|
|
25
25
|
"uploads": {{ config.uploads_dir | cc_jsonify }},
|
26
26
|
"plugins": {{ config.plugins_dir | cc_jsonify }},
|
27
27
|
"data": {{ config.data_dir | cc_jsonify }},
|
28
|
+
"pages": "",
|
28
29
|
"collections": {{ config.collections_dir | cc_jsonify }},
|
29
30
|
"includes": {{ config.includes_dir | cc_jsonify }},
|
30
31
|
"layouts": {{ config.layouts_dir | cc_jsonify }}
|
@@ -8,7 +8,7 @@
|
|
8
8
|
"include": {{ config.include | cc_jsonify }},
|
9
9
|
"exclude": {{ config.exclude | cc_jsonify }},
|
10
10
|
{% if config.baseurl %}"base-url": {{ config.baseurl | cc_jsonify }},{% endif %}
|
11
|
-
|
11
|
+
"collections": {{ collections | cc_jsonify: 'collections' }},
|
12
12
|
{% if config._comments %}"comments": {{ config._comments | cc_jsonify }},{% endif %}
|
13
13
|
{% if config._options %}"input-options": {{ config._options | cc_jsonify }},{% endif %}
|
14
14
|
{% if config.defaults %}"defaults": {{ config.defaults | cc_jsonify }},{% endif %}
|
@@ -25,6 +25,7 @@
|
|
25
25
|
"uploads": {{ config.uploads_dir | cc_jsonify }},
|
26
26
|
"plugins": {{ config.plugins_dir | cc_jsonify }},
|
27
27
|
"data": {{ config.data_dir | cc_jsonify }},
|
28
|
+
"pages": "",
|
28
29
|
"collections": {{ config.collections_dir | cc_jsonify }},
|
29
30
|
"includes": {{ config.includes_dir | cc_jsonify }},
|
30
31
|
"layouts": {{ config.layouts_dir | cc_jsonify }}
|
@@ -12,9 +12,7 @@
|
|
12
12
|
{% if config.baseurl -%}
|
13
13
|
"base-url": {{ config.baseurl | cc_jsonify }},
|
14
14
|
{%- endif %}
|
15
|
-
{
|
16
|
-
"collections": {{ config.collections | cc_jsonify: 'collections' }},
|
17
|
-
{%- endif %}
|
15
|
+
"collections": {{ collections | cc_jsonify: 'collections' }},
|
18
16
|
{% if config._comments -%}
|
19
17
|
"comments": {{ config._comments | cc_jsonify }},
|
20
18
|
{%- endif %}
|
@@ -43,6 +41,7 @@
|
|
43
41
|
"uploads": {{ config.uploads_dir | cc_jsonify }},
|
44
42
|
"plugins": {{ config.plugins_dir | cc_jsonify }},
|
45
43
|
"data": {{ config.data_dir | cc_jsonify }},
|
44
|
+
"pages": "",
|
46
45
|
"collections": {{ config.collections_dir | cc_jsonify }},
|
47
46
|
"includes": {{ config.includes_dir | cc_jsonify }},
|
48
47
|
"layouts": {{ config.layouts_dir | cc_jsonify }}
|
@@ -18,10 +18,11 @@
|
|
18
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
19
|
{% elsif site.cloudcannon.data %}"data": {{ site.data | cc_jsonify }},{% endif %}
|
20
20
|
"collections": {
|
21
|
+
"drafts": {{ drafts | cc_jsonify }},
|
21
22
|
"posts": {{ site.posts | reverse | cc_jsonify }}{% if site.collections.size > 0 %},{% endif %}
|
22
23
|
{% for collection in site.collections %}"{{ collection[0] | xml_escape }}": {{ collection[1].docs | cc_jsonify }}{% unless forloop.last %},{% endunless %}
|
23
24
|
{% endfor %}
|
24
25
|
},
|
25
26
|
"pages": {{ site.pages | cc_jsonify }},
|
26
|
-
"static": {{ site.static_files | cc_static_files_jsonify }}
|
27
|
+
"static-pages": {{ site.static_files | cc_static_files_jsonify }}
|
27
28
|
}
|
@@ -18,9 +18,10 @@
|
|
18
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
19
|
{% elsif site.cloudcannon.data %}"data": {{ site.data | cc_jsonify }},{% endif %}
|
20
20
|
"collections": {
|
21
|
+
"drafts": {{ drafts | cc_jsonify }}{% if site.collections.size > 0 %},{% endif %}
|
21
22
|
{% for collection in site.collections %}"{{ collection.label | xml_escape }}": {{ collection.docs | cc_jsonify }}{% unless forloop.last %},{% endunless %}
|
22
23
|
{% endfor %}
|
23
24
|
},
|
24
25
|
"pages": {{ site.pages | cc_jsonify }},
|
25
|
-
"static": {{ site.static_files | cc_static_files_jsonify }}
|
26
|
+
"static-pages": {{ site.static_files | cc_static_files_jsonify }}
|
26
27
|
}
|
@@ -30,11 +30,12 @@
|
|
30
30
|
"data": {{ site.data | cc_jsonify }},
|
31
31
|
{%- endif %}
|
32
32
|
"collections": {
|
33
|
+
"drafts": {{ drafts | cc_jsonify }}{% if site.collections.size > 0 %},{% endif %}
|
33
34
|
{%- for collection in site.collections -%}
|
34
35
|
"{{ collection.label | xml_escape }}": {{ collection.docs | cc_jsonify }}
|
35
36
|
{%- unless forloop.last %},{% endunless %}
|
36
37
|
{%- endfor -%}
|
37
38
|
},
|
38
39
|
"pages": {{ site.pages | cc_jsonify }},
|
39
|
-
"static": {{ site.static_files | cc_static_files_jsonify }}
|
40
|
+
"static-pages": {{ site.static_files | cc_static_files_jsonify }}
|
40
41
|
}
|
@@ -17,7 +17,7 @@ module CloudCannonJekyll
|
|
17
17
|
config = config.fix_common_issues if config.respond_to? :fix_common_issues
|
18
18
|
config = config.add_default_excludes if config.respond_to? :add_default_excludes
|
19
19
|
|
20
|
-
key = Jekyll::VERSION.start_with?("2") ? "gems" : "plugins"
|
20
|
+
key = Jekyll::VERSION.start_with?("2.") ? "gems" : "plugins"
|
21
21
|
|
22
22
|
config[key] = Array(config[key])
|
23
23
|
config[key].push("cloudcannon-jekyll") unless config[key].include? "cloudcannon-jekyll"
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require "jekyll"
|
4
4
|
require "fileutils"
|
5
|
+
require_relative "reader"
|
5
6
|
|
6
7
|
module CloudCannonJekyll
|
7
8
|
# Generates JSON files containing build config and build output details
|
@@ -10,25 +11,119 @@ module CloudCannonJekyll
|
|
10
11
|
|
11
12
|
def generate(site)
|
12
13
|
@site = site
|
14
|
+
@reader = Reader.new(@site)
|
15
|
+
|
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
|
13
22
|
|
14
23
|
payload = @site.site_payload.merge({
|
15
24
|
"gem_version" => CloudCannonJekyll::VERSION,
|
25
|
+
})
|
26
|
+
|
27
|
+
drafts = add_blogging_config(collections_config)
|
28
|
+
add_collection_paths(collections_config)
|
29
|
+
add_data_config(collections_config)
|
30
|
+
|
31
|
+
generate_file("config", payload.merge({
|
16
32
|
"pwd" => Dir.pwd,
|
17
33
|
"config" => @site.config,
|
18
|
-
|
34
|
+
"collections" => collections_config,
|
35
|
+
}))
|
19
36
|
|
20
|
-
generate_file("details", payload
|
21
|
-
|
37
|
+
generate_file("details", payload.merge({
|
38
|
+
"drafts" => drafts,
|
39
|
+
}))
|
40
|
+
end
|
22
41
|
|
23
|
-
|
24
|
-
|
25
|
-
|
42
|
+
def collections_dir
|
43
|
+
return "" if Jekyll::VERSION.start_with? "2."
|
44
|
+
|
45
|
+
@site.config["collections_dir"] || ""
|
46
|
+
end
|
47
|
+
|
48
|
+
def data_dir
|
49
|
+
@site.config["data_dir"] || "_data"
|
50
|
+
end
|
51
|
+
|
52
|
+
# rubocop:disable Metrics/AbcSize
|
53
|
+
def add_category_folder_config(collections_config, posts_config = {})
|
54
|
+
posts = @site.posts || @site.collections["posts"]
|
55
|
+
docs = posts.class.method_defined?(:docs) ? posts.docs : posts
|
56
|
+
seen = {}
|
57
|
+
|
58
|
+
docs.map do |post|
|
59
|
+
parts = post.relative_path.split("/_posts/")
|
60
|
+
path = parts.first
|
61
|
+
|
62
|
+
# Ignore unless it's an unseen category folder post
|
63
|
+
next if parts.length < 2 || path.empty? || seen[path]
|
64
|
+
|
65
|
+
# Could check this to ensure raw files exist since posts can be generated without files
|
66
|
+
# next if @reader.read_posts(parts[0]).empty?
|
67
|
+
|
68
|
+
seen[path] = true
|
69
|
+
folder = path.sub(%r!^\/+!, "")
|
70
|
+
collections_path = "#{collections_dir}/#{folder}".gsub(%r!\/+!, "/").sub(%r!^\/+!, "")
|
71
|
+
|
72
|
+
collections_config["#{folder}/posts"] = posts_config.merge({
|
73
|
+
"_path" => "#{collections_path}/_posts",
|
74
|
+
})
|
75
|
+
|
76
|
+
# Adding the category draft config like this isn't ideal, since you could have drafts
|
77
|
+
# without posts, but it's a decent trade off vs looking for _drafts folders
|
78
|
+
collections_config["#{folder}/drafts"] = posts_config.merge({
|
79
|
+
"_path" => "#{collections_path}/_drafts",
|
80
|
+
})
|
81
|
+
|
82
|
+
path
|
83
|
+
end
|
84
|
+
end
|
85
|
+
# rubocop:enable Metrics/AbcSize
|
86
|
+
|
87
|
+
# Add data to collections config if raw data files exist
|
88
|
+
def add_data_config(collections_config)
|
89
|
+
data_files = @reader.read_data(data_dir)
|
90
|
+
collections_config["data"] = { "_path" => data_dir } if data_files&.keys&.any?
|
91
|
+
end
|
92
|
+
|
93
|
+
# Add posts/drafts to collections config
|
94
|
+
def add_blogging_config(collections_config)
|
95
|
+
collections_config["posts"] = { "output" => true } if Jekyll::VERSION.start_with? "2."
|
96
|
+
drafts = @reader.read_drafts(collections_dir)
|
97
|
+
|
98
|
+
if collections_config.key?("posts")
|
99
|
+
collections_config["drafts"] = collections_config["posts"]&.dup || {}
|
100
|
+
elsif drafts.any?
|
101
|
+
collections_config["drafts"] = {}
|
102
|
+
end
|
103
|
+
|
104
|
+
folders = add_category_folder_config(collections_config, collections_config["posts"])
|
105
|
+
folders.compact.each do |folder|
|
106
|
+
drafts += @reader.read_drafts(folder)
|
107
|
+
end
|
108
|
+
|
109
|
+
drafts
|
110
|
+
end
|
111
|
+
|
112
|
+
# Add _path to each collection config
|
113
|
+
def add_collection_paths(collections_config)
|
114
|
+
collections_config.each do |key, collection|
|
115
|
+
next if collection.key?("_path")
|
116
|
+
|
117
|
+
collection["_path"] = File.join(collections_dir, "_#{key}").sub(%r!^\/+!, "")
|
118
|
+
end
|
26
119
|
end
|
27
120
|
|
28
121
|
def generate_file(filename, data)
|
29
122
|
dest = destination_path(filename)
|
30
123
|
FileUtils.mkdir_p(File.dirname(dest))
|
31
124
|
File.open(dest, "w") { |file| file.write(file_content(filename, data)) }
|
125
|
+
@site.keep_files ||= []
|
126
|
+
@site.keep_files << path(filename)
|
32
127
|
end
|
33
128
|
|
34
129
|
def version_path_suffix
|
@@ -6,7 +6,6 @@ module CloudCannonJekyll
|
|
6
6
|
# Filter for converting Jekyll objects into JSON
|
7
7
|
module JsonifyFilter
|
8
8
|
STATIC_EXTENSIONS = [".html", ".htm"].freeze
|
9
|
-
STATIC_PATHS = ["/robots.txt", "/sitemap.xml"].freeze
|
10
9
|
|
11
10
|
CC_JSONIFY_KEY_SWAPS = {
|
12
11
|
"collections" => {
|
@@ -46,17 +45,14 @@ module CloudCannonJekyll
|
|
46
45
|
end
|
47
46
|
|
48
47
|
def self.static_file_to_json(input, depth, max_depth)
|
48
|
+
path = input.relative_path.sub(%r!^\/+!, "")
|
49
|
+
url = Jekyll::VERSION.start_with?("2.") ? "/#{path}" : input.url
|
50
|
+
|
49
51
|
out = [
|
50
|
-
"\"
|
51
|
-
"\"
|
52
|
+
"\"path\": #{JsonifyFilter.to_json(path, depth, max_depth)}",
|
53
|
+
"\"url\": #{JsonifyFilter.to_json(url, depth, max_depth)}",
|
52
54
|
]
|
53
55
|
|
54
|
-
# modified_time isn't defined in Jekyll 2.4.0
|
55
|
-
if input.respond_to? :modified_time
|
56
|
-
file_json = JsonifyFilter.to_json(input.modified_time, depth, max_depth)
|
57
|
-
out.push("\"modified_time\": #{file_json}")
|
58
|
-
end
|
59
|
-
|
60
56
|
"{#{out.join(",")}}"
|
61
57
|
end
|
62
58
|
|
@@ -77,7 +73,6 @@ module CloudCannonJekyll
|
|
77
73
|
prevent = %w(dir name path url date id categories tags)
|
78
74
|
|
79
75
|
out = [
|
80
|
-
"\"dir\": #{JsonifyFilter.to_json(input.dir, depth, max_depth)}",
|
81
76
|
"\"name\": #{JsonifyFilter.to_json(input.name, depth, max_depth)}",
|
82
77
|
"\"path\": #{JsonifyFilter.to_json(input.path, depth, max_depth)}",
|
83
78
|
"\"url\": #{JsonifyFilter.to_json(input.url, depth, max_depth)}",
|
@@ -95,7 +90,6 @@ module CloudCannonJekyll
|
|
95
90
|
prevent = %w(dir name path url)
|
96
91
|
|
97
92
|
out = [
|
98
|
-
"\"dir\": #{JsonifyFilter.to_json(input.dir, depth, max_depth)}",
|
99
93
|
"\"name\": #{JsonifyFilter.to_json(input.name, depth, max_depth)}",
|
100
94
|
"\"path\": #{JsonifyFilter.to_json(input.path, depth, max_depth)}",
|
101
95
|
"\"url\": #{JsonifyFilter.to_json(input.url, depth, max_depth)}",
|
@@ -113,12 +107,10 @@ module CloudCannonJekyll
|
|
113
107
|
end
|
114
108
|
|
115
109
|
def self.document_to_json(input, depth, max_depth)
|
116
|
-
prevent = %w(dir
|
117
|
-
path_json = JsonifyFilter.to_json(input.relative_path, depth, max_depth)
|
110
|
+
prevent = %w(dir relative_path url collection)
|
118
111
|
|
119
112
|
out = [
|
120
|
-
"\"path\": #{
|
121
|
-
"\"relative_path\": #{path_json}",
|
113
|
+
"\"path\": #{JsonifyFilter.to_json(input.relative_path, depth, max_depth)}",
|
122
114
|
"\"url\": #{JsonifyFilter.to_json(input.url, depth, max_depth)}",
|
123
115
|
]
|
124
116
|
|
@@ -128,7 +120,6 @@ module CloudCannonJekyll
|
|
128
120
|
out.push("\"collection\": #{collection_json}")
|
129
121
|
end
|
130
122
|
|
131
|
-
# id isn't defined in Jekyll 2.4.0
|
132
123
|
if input.respond_to? :id
|
133
124
|
out.push("\"id\": #{JsonifyFilter.to_json(input.id, depth, max_depth)}")
|
134
125
|
end
|
@@ -203,9 +194,7 @@ module CloudCannonJekyll
|
|
203
194
|
|
204
195
|
def cc_static_files_jsonify(input)
|
205
196
|
out = input.map do |page|
|
206
|
-
|
207
|
-
|
208
|
-
JsonifyFilter.to_json(page, 1)
|
197
|
+
JsonifyFilter.to_json(page, 1) if STATIC_EXTENSIONS.include?(page.extname)
|
209
198
|
end
|
210
199
|
|
211
200
|
out.compact!
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "jekyll"
|
4
|
+
require_relative "readers/old-data-reader"
|
5
|
+
require_relative "readers/data-reader"
|
6
|
+
|
7
|
+
module CloudCannonJekyll
|
8
|
+
# Wraps read functions into one class
|
9
|
+
class Reader
|
10
|
+
attr_reader :site
|
11
|
+
|
12
|
+
def initialize(site)
|
13
|
+
@site = site
|
14
|
+
end
|
15
|
+
|
16
|
+
def read_data(dir = "_data")
|
17
|
+
# DataReader doesn't exist in old versions of Jekyll
|
18
|
+
if Jekyll::VERSION.start_with? "2."
|
19
|
+
CloudCannonJekyll::OldDataReader.new(@site).read(dir)
|
20
|
+
else
|
21
|
+
CloudCannonJekyll::DataReader.new(@site).read(dir)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def read_drafts(dir = "")
|
26
|
+
# PostReader doesn't exist in old versions of Jekyll
|
27
|
+
if Jekyll::VERSION.start_with? "2."
|
28
|
+
@site.read_content(dir, "_drafts", Jekyll::Draft)
|
29
|
+
else
|
30
|
+
Jekyll::PostReader.new(@site).read_drafts(dir)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def read_posts(dir = "")
|
35
|
+
# PostReader doesn't exist in old versions of Jekyll
|
36
|
+
if Jekyll::VERSION.start_with? "2."
|
37
|
+
@site.read_content(dir, "_posts", Jekyll::Post)
|
38
|
+
else
|
39
|
+
Jekyll::PostReader.new(@site).read_posts(dir)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
unless Jekyll::VERSION.start_with? "2."
|
4
|
+
require "jekyll"
|
5
|
+
|
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
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
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
|
17
|
+
|
18
|
+
def read(dir)
|
19
|
+
base = Jekyll.sanitized_path(@site.source, dir)
|
20
|
+
read_data_to(base, @content)
|
21
|
+
@content
|
22
|
+
end
|
23
|
+
|
24
|
+
def read_data_to(dir, data)
|
25
|
+
return unless File.directory?(dir) && (!@safe || !File.symlink?(dir))
|
26
|
+
|
27
|
+
entries = Dir.chdir(dir) do
|
28
|
+
Dir["*.{yaml,yml,json,csv}"] + Dir["*"].select { |fn| File.directory?(fn) }
|
29
|
+
end
|
30
|
+
|
31
|
+
entries.each do |entry|
|
32
|
+
path = Jekyll.sanitized_path(dir, entry)
|
33
|
+
next if File.symlink?(path) && @safe
|
34
|
+
|
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
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def read_data_file(path)
|
45
|
+
{
|
46
|
+
"path" => path,
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
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
|
55
|
+
end
|
56
|
+
end
|
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: 1.
|
4
|
+
version: 1.5.5
|
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
|
+
date: 2020-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -107,6 +107,7 @@ executables: []
|
|
107
107
|
extensions: []
|
108
108
|
extra_rdoc_files: []
|
109
109
|
files:
|
110
|
+
- ".github/workflows/stale.yml"
|
110
111
|
- ".gitignore"
|
111
112
|
- ".reek.yml"
|
112
113
|
- ".rspec"
|
@@ -129,6 +130,9 @@ files:
|
|
129
130
|
- lib/cloudcannon-jekyll/generator.rb
|
130
131
|
- lib/cloudcannon-jekyll/jsonify-filter.rb
|
131
132
|
- lib/cloudcannon-jekyll/page-without-a-file.rb
|
133
|
+
- lib/cloudcannon-jekyll/reader.rb
|
134
|
+
- lib/cloudcannon-jekyll/readers/data-reader.rb
|
135
|
+
- lib/cloudcannon-jekyll/readers/old-data-reader.rb
|
132
136
|
- lib/cloudcannon-jekyll/version.rb
|
133
137
|
- script/ci-smoke-test
|
134
138
|
- script/cibuild
|