cloudcannon-jekyll 0.5.0 → 1.0.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 +1 -2
- data/.rubocop.yml +2 -24
- data/.travis.yml +3 -2
- data/Gemfile +0 -2
- data/HISTORY.md +3 -83
- data/README.md +1 -1
- data/cloudcannon-jekyll.gemspec +5 -6
- data/lib/cloudcannon-jekyll/_cloudcannon/details-2.x.json +25 -0
- data/lib/cloudcannon-jekyll/_cloudcannon/details-3.0.x.json +24 -0
- data/lib/cloudcannon-jekyll/_cloudcannon/details.json +28 -0
- data/lib/cloudcannon-jekyll/configuration.rb +1 -2
- data/lib/cloudcannon-jekyll/generator.rb +18 -147
- data/lib/cloudcannon-jekyll/page-without-a-file.rb +0 -1
- data/lib/cloudcannon-jekyll/safe-jsonify-filter.rb +169 -0
- data/lib/cloudcannon-jekyll/version.rb +1 -1
- data/lib/cloudcannon-jekyll.rb +10 -8
- data/script/cibuild +2 -1
- data/script/release +5 -7
- data/script/test +0 -1
- metadata +14 -33
- data/.github/workflows/stale.yml +0 -19
- data/.reek.yml +0 -6
- data/lib/cloudcannon-jekyll/_cloudcannon/info-2.x.json +0 -76
- data/lib/cloudcannon-jekyll/_cloudcannon/info-3.0-4.x.json +0 -75
- data/lib/cloudcannon-jekyll/_cloudcannon/info.json +0 -88
- data/lib/cloudcannon-jekyll/jsonify-filter.rb +0 -232
- data/lib/cloudcannon-jekyll/reader.rb +0 -43
- data/lib/cloudcannon-jekyll/readers/data-reader.rb +0 -20
- data/lib/cloudcannon-jekyll/readers/old-data-reader.rb +0 -57
- data/script/ci-smoke-test +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acbff58768a2a1c6d143ed8c0fe84cc1e3a6dc147e449fa91b69d24ea85655b8
|
4
|
+
data.tar.gz: 778145a334b54d304ff601c3547c397a6955b9edf7fa73e393565aa7a0a1d46b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfd7cd98ba79c5b49e312f75f3ade2a844565f78e8a45d75e52d1776bbbf1c34b13aa9bac5de6a2b20314d2538fe80a261e2154dab4eeaf27187f639984e7700
|
7
|
+
data.tar.gz: cf9f07c980a416af440a2ba1b7f6ae20a420b8fe758752d736ad88878bf516bd8adb3bf7141725abfd100ff2c08cfc030db2f3d2753e3fff5416f9a8c7b95cd0
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -4,7 +4,7 @@ inherit_gem:
|
|
4
4
|
rubocop-jekyll: .rubocop.yml
|
5
5
|
|
6
6
|
AllCops:
|
7
|
-
TargetRubyVersion: 2.
|
7
|
+
TargetRubyVersion: 2.6
|
8
8
|
Include:
|
9
9
|
- lib/**/*.rb
|
10
10
|
|
@@ -20,30 +20,8 @@ AllCops:
|
|
20
20
|
- script/**/*
|
21
21
|
- vendor/**/*
|
22
22
|
- gemfiles/**/*
|
23
|
+
- lib/cloudcannon-jekyll/safe-jsonify-filter.rb # TODO remove this and fix warnings
|
23
24
|
|
24
25
|
Naming/MemoizedInstanceVariableName:
|
25
26
|
Exclude:
|
26
27
|
- lib/cloudcannon-jekyll/page-without-a-file.rb
|
27
|
-
|
28
|
-
Metrics/CyclomaticComplexity:
|
29
|
-
Exclude:
|
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
|
32
|
-
|
33
|
-
Metrics/PerceivedComplexity:
|
34
|
-
Exclude:
|
35
|
-
- lib/cloudcannon-jekyll/jsonify-filter.rb # TODO remove this and fix warnings
|
36
|
-
|
37
|
-
Metrics/AbcSize:
|
38
|
-
Exclude:
|
39
|
-
- lib/cloudcannon-jekyll/jsonify-filter.rb # TODO remove this and fix warnings
|
40
|
-
|
41
|
-
# This is excluded since the ruby target is 2.3.8 which doesn't support String.match?(Regexp)
|
42
|
-
Performance/RegexpMatch:
|
43
|
-
Exclude:
|
44
|
-
- lib/cloudcannon-jekyll/generator.rb
|
45
|
-
|
46
|
-
# This is excluded since Jekyll used this and we need to check for it
|
47
|
-
Lint/UnifiedInteger:
|
48
|
-
Exclude:
|
49
|
-
- lib/cloudcannon-jekyll/jsonify-filter.rb
|
data/.travis.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
language: ruby
|
2
2
|
cache: bundler
|
3
3
|
rvm:
|
4
|
-
- 2.
|
4
|
+
- 2.6
|
5
5
|
|
6
6
|
before_install:
|
7
7
|
- gem update --system
|
@@ -15,4 +15,5 @@ env:
|
|
15
15
|
matrix:
|
16
16
|
- JEKYLL_VERSION="2.4.0"
|
17
17
|
- JEKYLL_VERSION="3.0.0"
|
18
|
-
- JEKYLL_VERSION="3.
|
18
|
+
- JEKYLL_VERSION="3.8.5"
|
19
|
+
- JEKYLL_VERSION="4.0.0"
|
data/Gemfile
CHANGED
data/HISTORY.md
CHANGED
@@ -1,87 +1,7 @@
|
|
1
|
-
# 0.
|
1
|
+
# 1.0.0
|
2
2
|
|
3
|
-
*
|
4
|
-
*
|
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
|
-
|
28
|
-
# 0.3.1
|
29
|
-
|
30
|
-
* Fix for empty collection configurations
|
31
|
-
* Added max depth parameter for jsonify filter and increase it for array structures in config output
|
32
|
-
|
33
|
-
# 0.3.0
|
34
|
-
|
35
|
-
* Add empty paths.pages
|
36
|
-
* Added drafts to collections in details
|
37
|
-
* Added drafts and data to collections in config
|
38
|
-
* Added category folder drafts and posts to collections in config
|
39
|
-
* Added `_path` field to each collection definition in config
|
40
|
-
* Removed some unused fields
|
41
|
-
* Renamed static to static-pages in details and removed `robots.txt` and `sitemap.xml` exceptions
|
42
|
-
* Add `url` to static-pages
|
43
|
-
* Normalise `_path` in static-pages
|
44
|
-
|
45
|
-
# 0.2.2
|
46
|
-
|
47
|
-
* Added JSON handling for integers in hash keys
|
48
|
-
* Fix typo for collections key in older Jekyll versions
|
49
|
-
* Change date format to ISO8601
|
50
|
-
* Validate against new version of config schema
|
51
|
-
|
52
|
-
# 0.2.1
|
53
|
-
|
54
|
-
* Add gem information and time to output config file
|
55
|
-
* Fix missing in-place compact
|
56
|
-
* Fix source being output as full path on disk
|
57
|
-
* Read content for output config file directly from site config
|
58
|
-
|
59
|
-
# 0.2.0
|
60
|
-
|
61
|
-
* Add defaults and input-options keys to config output
|
62
|
-
* Add more ignore keys for legacy select data filter
|
63
|
-
* Reduce methods added from other plugins clashing
|
64
|
-
* Fix invalid output when unsupported class found
|
65
|
-
|
66
|
-
# 0.1.0
|
67
|
-
|
68
|
-
* Add output config file
|
69
|
-
* Add support for including only specified `data` keys
|
70
|
-
* Fix invalid JSON issue for sites built with Jekyll 2 and no collections
|
71
|
-
* Change module load style for easier dropping into _plugins
|
72
|
-
|
73
|
-
# 0.0.8
|
74
|
-
|
75
|
-
* Removed unsupported Jekyll test targets
|
76
|
-
|
77
|
-
# 0.0.7
|
78
|
-
|
79
|
-
* Fix invalid JSON issue for sites built with Jekyll 2 and no collections
|
80
|
-
|
81
|
-
# 0.0.6
|
82
|
-
|
83
|
-
* Fixed unsupported Fixnum for Ruby 2.3
|
84
|
-
* Fixed reference to unsupported String::match? for Ruby 2.3
|
3
|
+
* Initial release
|
4
|
+
* Dropped support for ruby 2.3
|
85
5
|
|
86
6
|
# 0.0.5
|
87
7
|
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
A Jekyll plugin to create CloudCannon editor details.
|
4
4
|
|
5
|
-
[](https://travis-ci.com/CloudCannon/cloudcannon-jekyll) [](https://badge.fury.io/rb/cloudcannon-jekyll)
|
6
6
|
|
7
7
|
## Usage
|
8
8
|
|
data/cloudcannon-jekyll.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# coding: utf-8
|
2
2
|
|
3
|
-
lib = File.expand_path("lib",
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
5
|
|
6
6
|
require "cloudcannon-jekyll/version"
|
@@ -19,11 +19,10 @@ Gem::Specification.new do |spec|
|
|
19
19
|
all_files = `git ls-files -z`.split("\x0")
|
20
20
|
spec.files = all_files.reject { |f| f.match(%r!^(test|spec|features)/!) }
|
21
21
|
|
22
|
-
spec.add_dependency "jekyll", ">= 2.4.0", "<
|
22
|
+
spec.add_dependency "jekyll", ">= 2.4.0", "< 5"
|
23
23
|
|
24
|
-
spec.add_development_dependency "json_schemer", "~> 0.2.4"
|
25
24
|
spec.add_development_dependency "rake", "~> 13.0"
|
26
25
|
spec.add_development_dependency "rspec", "~> 3.9"
|
27
|
-
spec.add_development_dependency "rubocop", "~> 0.
|
28
|
-
spec.add_development_dependency "rubocop-jekyll", "~> 0.
|
26
|
+
spec.add_development_dependency "rubocop", "~> 0.71"
|
27
|
+
spec.add_development_dependency "rubocop-jekyll", "~> 0.10"
|
29
28
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
{
|
2
|
+
"time": {{ site.time | jsonify }},
|
3
|
+
"cloudcannon": {
|
4
|
+
"name": "cloudcannon-jekyll",
|
5
|
+
"version": {{ gem_version | jsonify }}
|
6
|
+
},
|
7
|
+
"generator": {
|
8
|
+
"name": "jekyll",
|
9
|
+
"version": {{ jekyll.version | jsonify }},
|
10
|
+
"environment": {{ jekyll.env | jsonify }},
|
11
|
+
"metadata": {
|
12
|
+
"markdown": {{ site.markdown | cc_safe_jsonify }},
|
13
|
+
"kramdown": {{ site.kramdown | cc_safe_jsonify }},
|
14
|
+
"commonmark": {{ site.commonmark | cc_safe_jsonify }}
|
15
|
+
}
|
16
|
+
},{% if site.cloudcannon.data %}
|
17
|
+
"data": {{ site.data | cc_safe_jsonify }},{% endif %}
|
18
|
+
"collections": {
|
19
|
+
"posts": {{ site.posts | reverse | cc_safe_jsonify }},
|
20
|
+
{% for collection in site.collections %}"{{ collection[0] | xml_escape }}": {{ collection[1].docs | cc_safe_jsonify }}{% unless forloop.last %},{% endunless %}
|
21
|
+
{% endfor %}
|
22
|
+
},
|
23
|
+
"pages": {{ site.pages | cc_safe_jsonify }},
|
24
|
+
"static": {{ site.static_files | cc_static_files_jsonify }}
|
25
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
{
|
2
|
+
"time": {{ site.time | jsonify }},
|
3
|
+
"cloudcannon": {
|
4
|
+
"name": "cloudcannon-jekyll",
|
5
|
+
"version": {{ gem_version | jsonify }}
|
6
|
+
},
|
7
|
+
"generator": {
|
8
|
+
"name": "jekyll",
|
9
|
+
"version": {{ jekyll.version | jsonify }},
|
10
|
+
"environment": {{ jekyll.env | jsonify }},
|
11
|
+
"metadata": {
|
12
|
+
"markdown": {{ site.markdown | cc_safe_jsonify }},
|
13
|
+
"kramdown": {{ site.kramdown | cc_safe_jsonify }},
|
14
|
+
"commonmark": {{ site.commonmark | cc_safe_jsonify }}
|
15
|
+
}
|
16
|
+
},{% if site.cloudcannon.data %}
|
17
|
+
"data": {{ site.data | cc_safe_jsonify }},{% endif %}
|
18
|
+
"collections": {
|
19
|
+
{% for collection in site.collections %}"{{ collection.label | xml_escape }}": {{ collection.docs | cc_safe_jsonify }}{% unless forloop.last %},{% endunless %}
|
20
|
+
{% endfor %}
|
21
|
+
},
|
22
|
+
"pages": {{ site.pages | cc_safe_jsonify }},
|
23
|
+
"static": {{ site.static_files | cc_static_files_jsonify }}
|
24
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
{
|
2
|
+
"time": {{ site.time | jsonify }},
|
3
|
+
"cloudcannon": {
|
4
|
+
"name": "cloudcannon-jekyll",
|
5
|
+
"version": {{ gem_version | jsonify }}
|
6
|
+
},
|
7
|
+
"generator": {
|
8
|
+
"name": "jekyll",
|
9
|
+
"version": {{ jekyll.version | jsonify }},
|
10
|
+
"environment": {{ jekyll.env | jsonify }},
|
11
|
+
"metadata": {
|
12
|
+
"markdown": {{ site.markdown | cc_safe_jsonify }},
|
13
|
+
"kramdown": {{ site.kramdown | cc_safe_jsonify }},
|
14
|
+
"commonmark": {{ site.commonmark | cc_safe_jsonify }}
|
15
|
+
}
|
16
|
+
},
|
17
|
+
{%- if site.cloudcannon.data %}
|
18
|
+
"data": {{ site.data | cc_safe_jsonify }},
|
19
|
+
{% endif %}
|
20
|
+
"collections": {
|
21
|
+
{% for collection in site.collections -%}
|
22
|
+
"{{ collection.label | xml_escape }}": {{ collection.docs | cc_safe_jsonify }}
|
23
|
+
{%- unless forloop.last %},{% endunless %}
|
24
|
+
{%- endfor %}
|
25
|
+
},
|
26
|
+
"pages": {{ site.pages | cc_safe_jsonify }},
|
27
|
+
"static": {{ site.static_files | cc_static_files_jsonify }}
|
28
|
+
}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module CloudCannonJekyll
|
4
|
-
# Processes Jekyll configuration to enable the plugin is run and fix common issues
|
5
4
|
class Configuration
|
6
5
|
def self.processed?(site)
|
7
6
|
site.instance_variable_get(:@_cloudcannon_jekyll_processed) == true
|
@@ -17,7 +16,7 @@ module CloudCannonJekyll
|
|
17
16
|
config = config.fix_common_issues if config.respond_to? :fix_common_issues
|
18
17
|
config = config.add_default_excludes if config.respond_to? :add_default_excludes
|
19
18
|
|
20
|
-
key = Jekyll::VERSION.start_with?("2
|
19
|
+
key = Jekyll::VERSION.start_with?("2") ? "gems" : "plugins"
|
21
20
|
|
22
21
|
config[key] = Array(config[key])
|
23
22
|
config[key].push("cloudcannon-jekyll") unless config[key].include? "cloudcannon-jekyll"
|
@@ -2,170 +2,41 @@
|
|
2
2
|
|
3
3
|
require "jekyll"
|
4
4
|
require "fileutils"
|
5
|
-
require_relative "reader"
|
6
5
|
|
7
6
|
module CloudCannonJekyll
|
8
|
-
# Generates JSON files containing build config and build output details
|
9
7
|
class Generator < Jekyll::Generator
|
10
|
-
# Override the Jekyll::Plugin spaceship to push our plugin to the very end
|
11
8
|
priority :lowest
|
12
|
-
def self.<=>(*)
|
13
|
-
1
|
14
|
-
end
|
15
9
|
|
16
10
|
def generate(site)
|
17
11
|
@site = site
|
18
|
-
|
19
|
-
|
20
|
-
collections_config = process_collections_config
|
21
|
-
|
22
|
-
payload = @site.site_payload.merge({
|
23
|
-
"gem_version" => CloudCannonJekyll::VERSION,
|
24
|
-
})
|
25
|
-
|
26
|
-
drafts = add_blogging_config(collections_config)
|
27
|
-
add_collection_paths(collections_config)
|
28
|
-
add_data_config(collections_config)
|
29
|
-
add_legacy_explore_groups
|
30
|
-
|
31
|
-
generate_file("info", payload.merge({
|
32
|
-
"pwd" => Dir.pwd,
|
33
|
-
"config" => @site.config,
|
34
|
-
"collections_config" => collections_config,
|
35
|
-
"drafts" => drafts,
|
36
|
-
}))
|
37
|
-
end
|
38
|
-
|
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
|
50
|
-
end
|
51
|
-
|
52
|
-
def collections_dir
|
53
|
-
return "" if Jekyll::VERSION.start_with? "2."
|
54
|
-
|
55
|
-
@site.config["collections_dir"] || ""
|
56
|
-
end
|
57
|
-
|
58
|
-
def data_dir
|
59
|
-
@site.config["data_dir"] || "_data"
|
60
|
-
end
|
61
|
-
|
62
|
-
# rubocop:disable Metrics/AbcSize
|
63
|
-
def add_category_folder_config(collections_config, posts_config = {})
|
64
|
-
posts = @site.posts || @site.collections["posts"]
|
65
|
-
docs = posts.class.method_defined?(:docs) ? posts.docs : posts
|
66
|
-
seen = {}
|
67
|
-
|
68
|
-
docs.map do |post|
|
69
|
-
parts = post.relative_path.split("/_posts/")
|
70
|
-
path = parts.first
|
71
|
-
|
72
|
-
# Ignore unless it's an unseen category folder post
|
73
|
-
next if parts.length < 2 || path.empty? || seen[path]
|
74
|
-
|
75
|
-
# Could check this to ensure raw files exist since posts can be generated without files
|
76
|
-
# next if @reader.read_posts(parts[0]).empty?
|
77
|
-
|
78
|
-
seen[path] = true
|
79
|
-
folder = path.sub(%r!^\/+!, "")
|
80
|
-
collections_path = "#{collections_dir}/#{folder}".gsub(%r!\/+!, "/").sub(%r!^\/+!, "")
|
81
|
-
|
82
|
-
collections_config["#{folder}/posts"] = posts_config.merge({
|
83
|
-
"path" => "#{collections_path}/_posts",
|
84
|
-
})
|
85
|
-
|
86
|
-
# Adding the category draft config like this isn't ideal, since you could have drafts
|
87
|
-
# without posts, but it's a decent trade off vs looking for _drafts folders
|
88
|
-
collections_config["#{folder}/drafts"] = posts_config.merge({
|
89
|
-
"path" => "#{collections_path}/_drafts",
|
90
|
-
})
|
91
|
-
|
92
|
-
path
|
93
|
-
end
|
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
|
103
|
-
|
104
|
-
# Add data to collections config if raw data files exist
|
105
|
-
def add_data_config(collections_config)
|
106
|
-
data_files = @reader.read_data(data_dir)
|
107
|
-
collections_config["data"] = { "path" => data_dir } if data_files&.keys&.any?
|
108
|
-
end
|
109
|
-
|
110
|
-
# Add posts/drafts to collections config
|
111
|
-
def add_blogging_config(collections_config)
|
112
|
-
collections_config["posts"] = { "output" => true } if Jekyll::VERSION.start_with? "2."
|
113
|
-
drafts = @reader.read_drafts(collections_dir)
|
114
|
-
|
115
|
-
if drafts.any? || (collections_config.key?("posts") && !collections_config.key?("drafts"))
|
116
|
-
collections_config["drafts"] = {}
|
117
|
-
end
|
118
|
-
|
119
|
-
folders = add_category_folder_config(collections_config, collections_config["posts"])
|
120
|
-
folders.compact.each do |folder|
|
121
|
-
drafts += @reader.read_drafts(folder)
|
122
|
-
end
|
123
|
-
|
124
|
-
drafts
|
125
|
-
end
|
126
|
-
|
127
|
-
# Add path to each collection config
|
128
|
-
def add_collection_paths(collections_config)
|
129
|
-
collections_config.each do |key, collection|
|
130
|
-
collection["path"] ||= File.join(collections_dir, "_#{key}").sub(%r!^\/+!, "")
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def generate_file(filename, data)
|
135
|
-
dest = destination_path(filename)
|
136
|
-
FileUtils.mkdir_p(File.dirname(dest))
|
137
|
-
File.open(dest, "w") { |file| file.write(file_content(filename, data)) }
|
12
|
+
FileUtils.mkdir_p(File.dirname(destination_path))
|
13
|
+
File.open(destination_path, "w") { |f| f.write(file_content) }
|
138
14
|
@site.keep_files ||= []
|
139
|
-
@site.keep_files <<
|
15
|
+
@site.keep_files << "_cloudcannon/details.json"
|
140
16
|
end
|
141
17
|
|
142
|
-
def
|
143
|
-
|
144
|
-
|
18
|
+
def source_path
|
19
|
+
path = "_cloudcannon/details.json"
|
20
|
+
path = "_cloudcannon/details-2.x.json" if Jekyll::VERSION.start_with? "2."
|
21
|
+
path = "_cloudcannon/details-3.0.x.json" if Jekyll::VERSION.match? %r!3\.[0-4]\.!
|
145
22
|
|
146
|
-
|
23
|
+
File.expand_path(path, File.dirname(__FILE__))
|
147
24
|
end
|
148
25
|
|
149
|
-
def
|
150
|
-
"_cloudcannon
|
26
|
+
def destination_path
|
27
|
+
Jekyll.sanitized_path(@site.dest, "_cloudcannon/details.json")
|
151
28
|
end
|
152
29
|
|
153
|
-
def
|
154
|
-
|
155
|
-
|
30
|
+
def file_content
|
31
|
+
json = PageWithoutAFile.new(@site, File.dirname(__FILE__), "", "_cloudcannon/details.json")
|
32
|
+
json.content = File.read(source_path)
|
156
33
|
|
157
|
-
|
158
|
-
|
159
|
-
|
34
|
+
json.data["layout"] = nil
|
35
|
+
json.data["sitemap"] = false
|
36
|
+
json.data["permalink"] = "/_cloudcannon/details.json"
|
160
37
|
|
161
|
-
|
162
|
-
|
163
|
-
page.content = File.read(source_path(filename))
|
164
|
-
page.data["layout"] = nil
|
165
|
-
page.data["sitemap"] = false
|
166
|
-
page.data["permalink"] = "/#{path(filename)}"
|
167
|
-
page.render({}, data)
|
168
|
-
page.output
|
38
|
+
json.render({}, @site.site_payload.merge("gem_version" => CloudCannonJekyll::VERSION))
|
39
|
+
json.output
|
169
40
|
end
|
170
41
|
end
|
171
42
|
end
|
@@ -0,0 +1,169 @@
|
|
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
|
+
].freeze
|
16
|
+
|
17
|
+
@document_types = [
|
18
|
+
Jekyll::Document,
|
19
|
+
Jekyll::Page,
|
20
|
+
Jekyll::VERSION.start_with?("2.") ? Jekyll::Post : nil,
|
21
|
+
].compact.freeze
|
22
|
+
|
23
|
+
def self.document_type?(input)
|
24
|
+
@document_types.include?(input.class)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.simple_type?(input)
|
28
|
+
@simple_types.include?(input.class) || [true, false].include?(input)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.static_file_to_json(input, depth)
|
32
|
+
out = [
|
33
|
+
"\"extname\": #{SafeJsonifyFilter.to_json(input.extname, depth + 1)}",
|
34
|
+
"\"path\": #{SafeJsonifyFilter.to_json(input.relative_path, depth + 1)}",
|
35
|
+
]
|
36
|
+
|
37
|
+
# modified_time isn't defined in Jekyll 2.4.0
|
38
|
+
if input.respond_to? :modified_time
|
39
|
+
out.push("\"modified_time\": #{SafeJsonifyFilter.to_json(input.modified_time, depth + 1)}")
|
40
|
+
end
|
41
|
+
|
42
|
+
"{#{out.join(",")}}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.document_data_to_json(data, out, prevent, depth)
|
46
|
+
prevent += %w(content output next previous excerpt)
|
47
|
+
|
48
|
+
data.map do |key, value|
|
49
|
+
unless prevent.include? key
|
50
|
+
out.push("\"#{key}\": #{SafeJsonifyFilter.to_json(value, depth + 1)}")
|
51
|
+
prevent.push(key)
|
52
|
+
end
|
53
|
+
end
|
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}\": #{SafeJsonifyFilter.to_json(value, depth + 1)}"
|
124
|
+
end
|
125
|
+
|
126
|
+
"{#{hash.join(",")}}"
|
127
|
+
end
|
128
|
+
|
129
|
+
def self.to_json(input, depth)
|
130
|
+
if depth > 8 || (depth > 2 && SafeJsonifyFilter.document_type?(input))
|
131
|
+
'"MAXIMUM_DEPTH"'
|
132
|
+
elsif SafeJsonifyFilter.simple_type?(input)
|
133
|
+
input.to_json
|
134
|
+
elsif input.is_a?(Jekyll::StaticFile)
|
135
|
+
SafeJsonifyFilter.static_file_to_json(input, depth)
|
136
|
+
elsif input.is_a?(Jekyll::Page)
|
137
|
+
SafeJsonifyFilter.page_to_json(input, depth)
|
138
|
+
elsif Jekyll::VERSION.start_with?("2.") && input.is_a?(Jekyll::Post)
|
139
|
+
SafeJsonifyFilter.legacy_post_to_json(input, depth)
|
140
|
+
elsif input.is_a?(Jekyll::Document)
|
141
|
+
SafeJsonifyFilter.document_to_json(input, depth)
|
142
|
+
elsif input.is_a?(Array)
|
143
|
+
SafeJsonifyFilter.array_to_json(input, depth)
|
144
|
+
elsif input.is_a?(Hash)
|
145
|
+
SafeJsonifyFilter.hash_to_json(input, depth)
|
146
|
+
else
|
147
|
+
"\"UNSUPPORTED:#{input.class}\""
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def cc_static_files_jsonify(input)
|
152
|
+
out = []
|
153
|
+
input.each do |page|
|
154
|
+
next if page.extname != ".html" &&
|
155
|
+
page.extname != ".htm" &&
|
156
|
+
page.path != "/robots.txt" &&
|
157
|
+
page.path != "/sitemap.xml"
|
158
|
+
|
159
|
+
out.push(SafeJsonifyFilter.to_json(page, 1))
|
160
|
+
end
|
161
|
+
|
162
|
+
"[#{out.join(",")}]"
|
163
|
+
end
|
164
|
+
|
165
|
+
def cc_safe_jsonify(input)
|
166
|
+
SafeJsonifyFilter.to_json(input, 0)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|