cloudcannon-jekyll 1.2.3 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61354938ea8f9342c8ce20f8e376dbf441fd97008ade2794eab7b3f1b8754c61
4
- data.tar.gz: ebd474b9bcb955654a4b62b7e2be99cb42f4de6cb42bb6d1a5828808ec1885ce
3
+ metadata.gz: bfc7e0f8ab3c22858387ee857fd9dc239abf81f34e4d270c6b6f91f9ea2b3901
4
+ data.tar.gz: 5865f787936da422eae9a53230479a624ce4be40b2011153d4f7fc838b8cc172
5
5
  SHA512:
6
- metadata.gz: 5b94f1c5e89f86faea90781700330f8845b140947af56f29aba021514959aef744f4d0213b904c7c9a3c5e84c9415f6d17a97ebe8bdf1259202370ce62203532
7
- data.tar.gz: bbb6c0ba8ec08c3f0e10877aea8e647246cb7660feb0a31968d108160b7be66802c1e23c5465df594766006bb942b47b47fc85709f5b1a12c1b739eca767a8ee
6
+ metadata.gz: 98f54fc42653327cc114fa4dcb0237d9daf3efa8424032cac8ccc0ca3d136b37081e96a7e1ef2bea69542b99ba60cade96bbbc11a675cdb8b761a3b73482bc2f
7
+ data.tar.gz: 823dae5fba82b7e8d8fd3c5377590ca6fe515bc1ee2909a7fdf6bbfa497b659e20f027ccf83c7ed2956ba88d9788309709ef9fb524148069db936d14ca9c2703
@@ -4,7 +4,7 @@ inherit_gem:
4
4
  rubocop-jekyll: .rubocop.yml
5
5
 
6
6
  AllCops:
7
- TargetRubyVersion: 2.6
7
+ TargetRubyVersion: 2.4
8
8
  Include:
9
9
  - lib/**/*.rb
10
10
 
@@ -20,8 +20,23 @@ AllCops:
20
20
  - script/**/*
21
21
  - vendor/**/*
22
22
  - gemfiles/**/*
23
- - lib/cloudcannon-jekyll/safe-jsonify-filter.rb # TODO remove this and fix warnings
24
23
 
25
24
  Naming/MemoizedInstanceVariableName:
26
25
  Exclude:
27
26
  - 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
+
32
+ Metrics/PerceivedComplexity:
33
+ Exclude:
34
+ - lib/cloudcannon-jekyll/jsonify-filter.rb # TODO remove this and fix warnings
35
+
36
+ Metrics/MethodLength:
37
+ Exclude:
38
+ - lib/cloudcannon-jekyll/jsonify-filter.rb # TODO remove this and fix warnings
39
+
40
+ Metrics/AbcSize:
41
+ Exclude:
42
+ - lib/cloudcannon-jekyll/jsonify-filter.rb # TODO remove this and fix warnings
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  gemspec
data/HISTORY.md CHANGED
@@ -1,3 +1,26 @@
1
+ # 1.4.0
2
+
3
+ * Fix typo for collections key in older Jekyll versions
4
+ * Change date format to ISO8601
5
+ * Validate against new version of config schema
6
+
7
+ # 1.3.3
8
+
9
+ * Add gem information and time to output config file
10
+
11
+ # 1.3.2
12
+
13
+ * Fix missing in-place compact
14
+
15
+ # 1.3.1
16
+
17
+ * Fix source being output as full path on disk
18
+ * Read content for output config file directly from site config
19
+
20
+ # 1.3.0
21
+
22
+ * Add defaults and input-options keys to config output
23
+
1
24
  # 1.2.3
2
25
 
3
26
  * Add more ignore keys for legacy select data filter
@@ -1,6 +1,6 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path("lib", __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  require "cloudcannon-jekyll/version"
@@ -23,9 +23,9 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_dependency "jekyll", ">= 2.4.0", "< 5"
25
25
 
26
+ spec.add_development_dependency "json_schemer", "~> 0.2.13"
26
27
  spec.add_development_dependency "rake", "~> 13.0"
27
28
  spec.add_development_dependency "rspec", "~> 3.9"
28
29
  spec.add_development_dependency "rubocop", "~> 0.80"
29
30
  spec.add_development_dependency "rubocop-jekyll", "~> 0.11"
30
- spec.add_development_dependency "json_schemer", "~> 0.2.13"
31
31
  end
@@ -5,10 +5,10 @@ require "jekyll"
5
5
  require_relative "cloudcannon-jekyll/page-without-a-file"
6
6
  require_relative "cloudcannon-jekyll/generator"
7
7
  require_relative "cloudcannon-jekyll/configuration"
8
- require_relative "cloudcannon-jekyll/safe-jsonify-filter"
8
+ require_relative "cloudcannon-jekyll/jsonify-filter"
9
9
  require_relative "cloudcannon-jekyll/version"
10
10
 
11
- Liquid::Template.register_filter(CloudCannonJekyll::SafeJsonifyFilter)
11
+ Liquid::Template.register_filter(CloudCannonJekyll::JsonifyFilter)
12
12
 
13
13
  # Hooks didn't exist in Jekyll 2 so we monkey patch to get an :after_reset hook
14
14
  if Jekyll::VERSION.start_with? "2"
@@ -1,43 +1,35 @@
1
1
  {
2
- {% if site.timezone %}"timezone": {{ site.timezone | jsonify }},{% endif %}
3
- "include": {{ site.include | jsonify }},
4
- "exclude": {{ site.exclude | jsonify }},
5
- {% if site.baseurl %}"base-url": {{ site.baseurl | jsonify }},{% endif %}
6
- "collections": {
7
- {% for collection in site.collections %}
8
- "{{ collection[0] | xml_escape }}": {
9
- "output": {{ collection[1].output | jsonify }},
10
- "_sort-key": {{ collection[1]._sort_key | jsonify }},
11
- "_subtext-key": {{ collection[1]._subtext_key | jsonify }},
12
- "_image-key": {{ collection[1]._image_key | jsonify }},
13
- "_image-size": {{ collection[1]._image_size | jsonify }},
14
- "_singular-name": {{ collection[1]._singular_name | jsonify }},
15
- "_singular-key": {{ collection[1]._singular_key | jsonify }},
16
- "_disable-add": {{ collection[1]._disable_add | jsonify }},
17
- "_icon": {{ collection[1]._icon | jsonify }},
18
- "_add-options": {{ collection[1]._add_options | cc_safe_jsonify }}
19
- }{% unless forloop.last %},{% endunless %}
20
- {% endfor %}
2
+ "time": {{ site.time | date_to_xmlschema | cc_jsonify }},
3
+ "cloudcannon": {
4
+ "name": "cloudcannon-jekyll",
5
+ "version": {{ gem_version | cc_jsonify }}
21
6
  },
22
- {% if site._comments %}"comments": {{ site._comments | cc_safe_jsonify }},{% endif %}
23
- {% if site._editor %}"editor": {
24
- "default-path": {{ site._editor.default_path | jsonify }}
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
+ {% if config.collections %}"collections": {{ config.collections | cc_jsonify: 'collections' }},{% endif %}
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 }}
25
17
  },{% endif %}
26
- {% if site._source_editor %}"source-editor": {
27
- "tab-size": {{ site._source_editor.tab_size | jsonify }},
28
- "show-gutter": {{ site._source_editor.show_gutter | jsonify }},
29
- "theme": {{ site._source_editor.theme | jsonify }}
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 }}
30
22
  },{% endif %}
31
- {% if site._explore %}"explore": {{ site._explore | cc_safe_jsonify }},{% endif %}
23
+ {% if config._explore %}"explore": {{ config._explore | cc_jsonify }},{% endif %}
32
24
  "paths": {
33
- "uploads": {{ site.uploads_dir | jsonify }},
34
- "plugins": {{ site.plugins_dir | jsonify }},
35
- "data": {{ site.data_dir | jsonify }},
36
- "collections": {{ site.collections_dir | jsonify }},
37
- "includes": {{ site.includes_dir | jsonify }},
38
- "layouts": {{ site.layouts_dir | jsonify }}
25
+ "uploads": {{ config.uploads_dir | cc_jsonify }},
26
+ "plugins": {{ config.plugins_dir | cc_jsonify }},
27
+ "data": {{ config.data_dir | cc_jsonify }},
28
+ "collections": {{ config.collections_dir | cc_jsonify }},
29
+ "includes": {{ config.includes_dir | cc_jsonify }},
30
+ "layouts": {{ config.layouts_dir | cc_jsonify }}
39
31
  },
40
- {% if site._array_structures %}"array-structures": {{ site._array_structures | cc_safe_jsonify }},{% endif %}
41
- {% assign select_data = site | cc_site_select_data_jsonify %}{% if select_data %}"select-data": {{ select_data }},{% endif %}
42
- "source": {{ site.source | jsonify }}
32
+ {% if config._array_structures %}"array-structures": {{ config._array_structures | cc_jsonify }},{% endif %}
33
+ {% assign select_data = config | cc_select_data_jsonify %}{% if select_data %}"select-data": {{ select_data }},{% endif %}
34
+ "source": {{ config.source | replace: pwd, "" | cc_jsonify }}
43
35
  }
@@ -1,43 +1,35 @@
1
1
  {
2
- {% if site.timezone %}"timezone": {{ site.timezone | jsonify }},{% endif %}
3
- "include": {{ site.include | jsonify }},
4
- "exclude": {{ site.exclude | jsonify }},
5
- {% if site.baseurl %}"base-url": {{ site.baseurl | jsonify }},{% endif %}
6
- "collections": {
7
- {% for collection in site.collections %}
8
- "{{ collection.label | xml_escape }}": {
9
- "output": {{ collection.output | jsonify }},
10
- "_sort-key": {{ collection._sort_key | jsonify }},
11
- "_subtext-key": {{ collection._subtext_key | jsonify }},
12
- "_image-key": {{ collection._image_key | jsonify }},
13
- "_image-size": {{ collection._image_size | jsonify }},
14
- "_singular-name": {{ collection._singular_name | jsonify }},
15
- "_singular-key": {{ collection._singular_key | jsonify }},
16
- "_disable-add": {{ collection._disable_add | jsonify }},
17
- "_icon": {{ collection._icon | jsonify }},
18
- "_add-options": {{ collection._add_options | cc_safe_jsonify }}
19
- }{% unless forloop.last %},{% endunless %}
20
- {% endfor %}
2
+ "time": {{ site.time | date_to_xmlschema | cc_jsonify }},
3
+ "cloudcannon": {
4
+ "name": "cloudcannon-jekyll",
5
+ "version": {{ gem_version | cc_jsonify }}
21
6
  },
22
- {% if site._comments %}"comments": {{ site._comments | cc_safe_jsonify }},{% endif %}
23
- {% if site._editor %}"editor": {
24
- "default-path": {{ site._editor.default_path | jsonify }}
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
+ {% if config.collections %}"collections": {{ config.collections | cc_jsonify: 'collections' }},{% endif %}
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 }}
25
17
  },{% endif %}
26
- {% if site._source_editor %}"source-editor": {
27
- "tab-size": {{ site._source_editor.tab_size | jsonify }},
28
- "show-gutter": {{ site._source_editor.show_gutter | jsonify }},
29
- "theme": {{ site._source_editor.theme | jsonify }}
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 }}
30
22
  },{% endif %}
31
- {% if site._explore %}"explore": {{ site._explore | cc_safe_jsonify }},{% endif %}
23
+ {% if config._explore %}"explore": {{ config._explore | cc_jsonify }},{% endif %}
32
24
  "paths": {
33
- "uploads": {{ site.uploads_dir | jsonify }},
34
- "plugins": {{ site.plugins_dir | jsonify }},
35
- "data": {{ site.data_dir | jsonify }},
36
- "collections": {{ site.collections_dir | jsonify }},
37
- "includes": {{ site.includes_dir | jsonify }},
38
- "layouts": {{ site.layouts_dir | jsonify }}
25
+ "uploads": {{ config.uploads_dir | cc_jsonify }},
26
+ "plugins": {{ config.plugins_dir | cc_jsonify }},
27
+ "data": {{ config.data_dir | cc_jsonify }},
28
+ "collections": {{ config.collections_dir | cc_jsonify }},
29
+ "includes": {{ config.includes_dir | cc_jsonify }},
30
+ "layouts": {{ config.layouts_dir | cc_jsonify }}
39
31
  },
40
- {% if site._array_structures %}"array-structures": {{ site._array_structures | cc_safe_jsonify }},{% endif %}
41
- {% assign select_data = site | cc_site_select_data_jsonify %}{% if select_data %}"select-data": {{ select_data }},{% endif %}
42
- "source": {{ site.source | jsonify }}
32
+ {% if config._array_structures %}"array-structures": {{ config._array_structures | cc_jsonify }},{% endif %}
33
+ {% assign select_data = config | cc_select_data_jsonify %}{% if select_data %}"select-data": {{ select_data }},{% endif %}
34
+ "source": {{ config.source | replace: pwd, "" | cc_jsonify }}
43
35
  }
@@ -1,61 +1,58 @@
1
1
  {
2
- {% if site.timezone -%}
3
- "timezone": {{ site.timezone | jsonify }},
4
- {%- endif %}
5
- "include": {{ site.include | jsonify }},
6
- "exclude": {{ site.exclude | jsonify }},
7
- {% if site.baseurl -%}
8
- "base-url": {{ site.baseurl | jsonify }},
9
- {%- endif %}
10
- "collections": {
11
- {%- for collection in site.collections -%}
12
- "{{ collection.label | xml_escape }}": {
13
- "output": {{ collection.output | jsonify }},
14
- "_sort-key": {{ collection._sort_key | jsonify }},
15
- "_subtext-key": {{ collection._subtext_key | jsonify }},
16
- "_image-key": {{ collection._image_key | jsonify }},
17
- "_image-size": {{ collection._image_size | jsonify }},
18
- "_singular-name": {{ collection._singular_name | jsonify }},
19
- "_singular-key": {{ collection._singular_key | jsonify }},
20
- "_disable-add": {{ collection._disable_add | jsonify }},
21
- "_icon": {{ collection._icon | jsonify }},
22
- "_add-options": {{ collection._add_options | cc_safe_jsonify }}
23
- }
24
- {%- unless forloop.last %},{% endunless %}
25
- {%- endfor -%}
2
+ "time": {{ site.time | date_to_xmlschema | cc_jsonify }},
3
+ "cloudcannon": {
4
+ "name": "cloudcannon-jekyll",
5
+ "version": {{ gem_version | cc_jsonify }}
26
6
  },
27
- {% if site._comments -%}
28
- "comments": {{ site._comments | cc_safe_jsonify }},
7
+ {% if config.timezone -%}
8
+ "timezone": {{ config.timezone | cc_jsonify }},
29
9
  {%- endif %}
30
- {% if site._editor -%}
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
+ {% if config.collections -%}
16
+ "collections": {{ config.collections | cc_jsonify: 'collections' }},
17
+ {%- endif %}
18
+ {% if config._comments -%}
19
+ "comments": {{ config._comments | cc_jsonify }},
20
+ {%- endif %}
21
+ {% if config._options -%}
22
+ "input-options": {{ config._options | cc_jsonify }},
23
+ {%- endif %}
24
+ {% if config.defaults -%}
25
+ "defaults": {{ config.defaults | cc_jsonify }},
26
+ {%- endif %}
27
+ {% if config._editor -%}
31
28
  "editor": {
32
- "default-path": {{ site._editor.default_path | jsonify }}
29
+ "default-path": {{ config._editor.default_path | cc_jsonify }}
33
30
  },
34
31
  {%- endif %}
35
- {% if site._source_editor -%}
32
+ {% if config._source_editor -%}
36
33
  "source-editor": {
37
- "tab-size": {{ site._source_editor.tab_size | jsonify }},
38
- "show-gutter": {{ site._source_editor.show_gutter | jsonify }},
39
- "theme": {{ site._source_editor.theme | jsonify }}
34
+ "tab-size": {{ config._source_editor.tab_size | cc_jsonify }},
35
+ "show-gutter": {{ config._source_editor.show_gutter | cc_jsonify }},
36
+ "theme": {{ config._source_editor.theme | cc_jsonify }}
40
37
  },
41
38
  {%- endif %}
42
- {% if site._explore -%}
43
- "explore": {{ site._explore | cc_safe_jsonify }},
39
+ {% if config._explore -%}
40
+ "explore": {{ config._explore | cc_jsonify }},
44
41
  {%- endif %}
45
42
  "paths": {
46
- "uploads": {{ site.uploads_dir | jsonify }},
47
- "plugins": {{ site.plugins_dir | jsonify }},
48
- "data": {{ site.data_dir | jsonify }},
49
- "collections": {{ site.collections_dir | jsonify }},
50
- "includes": {{ site.includes_dir | jsonify }},
51
- "layouts": {{ site.layouts_dir | jsonify }}
43
+ "uploads": {{ config.uploads_dir | cc_jsonify }},
44
+ "plugins": {{ config.plugins_dir | cc_jsonify }},
45
+ "data": {{ config.data_dir | cc_jsonify }},
46
+ "collections": {{ config.collections_dir | cc_jsonify }},
47
+ "includes": {{ config.includes_dir | cc_jsonify }},
48
+ "layouts": {{ config.layouts_dir | cc_jsonify }}
52
49
  },
53
- {% if site._array_structures -%}
54
- "array-structures": {{ site._array_structures | cc_safe_jsonify }},
50
+ {% if config._array_structures -%}
51
+ "array-structures": {{ config._array_structures | cc_jsonify }},
55
52
  {%- endif %}
56
- {% assign select_data = site | cc_site_select_data_jsonify -%}
53
+ {% assign select_data = config | cc_select_data_jsonify -%}
57
54
  {% if select_data -%}
58
55
  "select-data": {{ select_data }},
59
56
  {%- endif %}
60
- "source": {{ site.source | jsonify }}
57
+ "source": {{ config.source | replace: pwd, "" | cc_jsonify }}
61
58
  }
@@ -1,27 +1,27 @@
1
1
  {
2
- "time": {{ site.time | jsonify }},
2
+ "time": {{ site.time | date_to_xmlschema | cc_jsonify }},
3
3
  "cloudcannon": {
4
4
  "name": "cloudcannon-jekyll",
5
- "version": {{ gem_version | jsonify }}
5
+ "version": {{ gem_version | cc_jsonify }}
6
6
  },
7
7
  "generator": {
8
8
  "name": "jekyll",
9
- "version": {{ jekyll.version | jsonify }},
10
- "environment": {{ jekyll.env | jsonify }},
9
+ "version": {{ jekyll.version | cc_jsonify }},
10
+ "environment": {{ jekyll.env | cc_jsonify }},
11
11
  "metadata": {
12
- "markdown": {{ site.markdown | cc_safe_jsonify }},
13
- "kramdown": {{ site.kramdown | cc_safe_jsonify }},
14
- "commonmark": {{ site.commonmark | cc_safe_jsonify }}
12
+ "markdown": {{ site.markdown | cc_jsonify }},
13
+ "kramdown": {{ site.kramdown | cc_jsonify }},
14
+ "commonmark": {{ site.commonmark | cc_jsonify }}
15
15
  }
16
16
  },{% if site.cloudcannon.data.first %}{% assign data_seen = false %}
17
17
  "data": {
18
- {% for data in site.data %}{% assign key = data[0] %}{% if site.cloudcannon.data[key] %}{% if data_seen %},{% endif %}{{ data[0] | cc_safe_jsonify }}: {{ data[1] | cc_safe_jsonify }}{% assign data_seen = true %}{% endif %}{% endfor %}},
19
- {% elsif site.cloudcannon.data %}"data": {{ site.data | cc_safe_jsonify }},{% endif %}
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
20
  "collections": {
21
- "posts": {{ site.posts | reverse | cc_safe_jsonify }}{% if site.collections.size > 0 %},{% endif %}
22
- {% for collection in site.collections %}"{{ collection[0] | xml_escape }}": {{ collection[1].docs | cc_safe_jsonify }}{% unless forloop.last %},{% endunless %}
21
+ "posts": {{ site.posts | reverse | cc_jsonify }}{% if site.collections.size > 0 %},{% endif %}
22
+ {% for collection in site.collections %}"{{ collection[0] | xml_escape }}": {{ collection[1].docs | cc_jsonify }}{% unless forloop.last %},{% endunless %}
23
23
  {% endfor %}
24
24
  },
25
- "pages": {{ site.pages | cc_safe_jsonify }},
25
+ "pages": {{ site.pages | cc_jsonify }},
26
26
  "static": {{ site.static_files | cc_static_files_jsonify }}
27
27
  }
@@ -1,26 +1,26 @@
1
1
  {
2
- "time": {{ site.time | jsonify }},
2
+ "time": {{ site.time | date_to_xmlschema | cc_jsonify }},
3
3
  "cloudcannon": {
4
4
  "name": "cloudcannon-jekyll",
5
- "version": {{ gem_version | jsonify }}
5
+ "version": {{ gem_version | cc_jsonify }}
6
6
  },
7
7
  "generator": {
8
8
  "name": "jekyll",
9
- "version": {{ jekyll.version | jsonify }},
10
- "environment": {{ jekyll.env | jsonify }},
9
+ "version": {{ jekyll.version | cc_jsonify }},
10
+ "environment": {{ jekyll.env | cc_jsonify }},
11
11
  "metadata": {
12
- "markdown": {{ site.markdown | cc_safe_jsonify }},
13
- "kramdown": {{ site.kramdown | cc_safe_jsonify }},
14
- "commonmark": {{ site.commonmark | cc_safe_jsonify }}
12
+ "markdown": {{ site.markdown | cc_jsonify }},
13
+ "kramdown": {{ site.kramdown | cc_jsonify }},
14
+ "commonmark": {{ site.commonmark | cc_jsonify }}
15
15
  }
16
16
  },{% if site.cloudcannon.data.first %}{% assign data_seen = false %}
17
17
  "data": {
18
- {% for data in site.data %}{% assign key = data[0] %}{% if site.cloudcannon.data[key] %}{% if data_seen %},{% endif %}{{ data[0] | cc_safe_jsonify }}: {{ data[1] | cc_safe_jsonify }}{% assign data_seen = true %}{% endif %}{% endfor %}},
19
- {% elsif site.cloudcannon.data %}"data": {{ site.data | cc_safe_jsonify }},{% endif %}
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
20
  "collections": {
21
- {% for collection in site.collections %}"{{ collection.label | xml_escape }}": {{ collection.docs | cc_safe_jsonify }}{% unless forloop.last %},{% endunless %}
21
+ {% for collection in site.collections %}"{{ collection.label | xml_escape }}": {{ collection.docs | cc_jsonify }}{% unless forloop.last %},{% endunless %}
22
22
  {% endfor %}
23
23
  },
24
- "pages": {{ site.pages | cc_safe_jsonify }},
24
+ "pages": {{ site.pages | cc_jsonify }},
25
25
  "static": {{ site.static_files | cc_static_files_jsonify }}
26
26
  }
@@ -1,17 +1,17 @@
1
1
  {
2
- "time": {{ site.time | jsonify }},
2
+ "time": {{ site.time | date_to_xmlschema | cc_jsonify }},
3
3
  "cloudcannon": {
4
4
  "name": "cloudcannon-jekyll",
5
- "version": {{ gem_version | jsonify }}
5
+ "version": {{ gem_version | cc_jsonify }}
6
6
  },
7
7
  "generator": {
8
8
  "name": "jekyll",
9
- "version": {{ jekyll.version | jsonify }},
10
- "environment": {{ jekyll.env | jsonify }},
9
+ "version": {{ jekyll.version | cc_jsonify }},
10
+ "environment": {{ jekyll.env | cc_jsonify }},
11
11
  "metadata": {
12
- "markdown": {{ site.markdown | cc_safe_jsonify }},
13
- "kramdown": {{ site.kramdown | cc_safe_jsonify }},
14
- "commonmark": {{ site.commonmark | cc_safe_jsonify }}
12
+ "markdown": {{ site.markdown | cc_jsonify }},
13
+ "kramdown": {{ site.kramdown | cc_jsonify }},
14
+ "commonmark": {{ site.commonmark | cc_jsonify }}
15
15
  }
16
16
  },
17
17
  {% if site.cloudcannon.data.first -%}
@@ -21,20 +21,20 @@
21
21
  {%- assign key = data[0] %}
22
22
  {%- if site.cloudcannon.data[key] %}
23
23
  {%- if data_seen %},{% endif -%}
24
- {{ data[0] | cc_safe_jsonify }}: {{ data[1] | cc_safe_jsonify }}
24
+ {{ data[0] | cc_jsonify }}: {{ data[1] | cc_jsonify }}
25
25
  {%- assign data_seen = true %}
26
26
  {%- endif %}
27
27
  {%- endfor -%}
28
28
  },
29
29
  {% elsif site.cloudcannon.data -%}
30
- "data": {{ site.data | cc_safe_jsonify }},
30
+ "data": {{ site.data | cc_jsonify }},
31
31
  {%- endif %}
32
32
  "collections": {
33
33
  {%- for collection in site.collections -%}
34
- "{{ collection.label | xml_escape }}": {{ collection.docs | cc_safe_jsonify }}
34
+ "{{ collection.label | xml_escape }}": {{ collection.docs | cc_jsonify }}
35
35
  {%- unless forloop.last %},{% endunless %}
36
36
  {%- endfor -%}
37
37
  },
38
- "pages": {{ site.pages | cc_safe_jsonify }},
38
+ "pages": {{ site.pages | cc_jsonify }},
39
39
  "static": {{ site.static_files | cc_static_files_jsonify }}
40
40
  }
@@ -10,10 +10,14 @@ module CloudCannonJekyll
10
10
  def generate(site)
11
11
  @site = site
12
12
 
13
- details_data = { "gem_version" => CloudCannonJekyll::VERSION }
14
-
15
- generate_file("details", @site.site_payload.merge(details_data))
16
- generate_file("config", @site.site_payload)
13
+ payload = @site.site_payload.merge({
14
+ "gem_version" => CloudCannonJekyll::VERSION,
15
+ "pwd" => Dir.pwd,
16
+ "config" => @site.config,
17
+ })
18
+
19
+ generate_file("details", payload)
20
+ generate_file("config", payload)
17
21
 
18
22
  @site.keep_files ||= []
19
23
  @site.keep_files << path("details")
@@ -0,0 +1,217 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll"
4
+
5
+ module CloudCannonJekyll
6
+ module JsonifyFilter
7
+ CC_JSONIFY_KEY_SWAPS = {
8
+ "collections" => {
9
+ "_sort_key" => "_sort-key",
10
+ "_subtext_key" => "_subtext-key",
11
+ "_image_key" => "_image-key",
12
+ "_image_size" => "_image-size",
13
+ "_singular_name" => "_singular-name",
14
+ "_singular_key" => "_singular-key",
15
+ "_disable_add" => "_disable-add",
16
+ "_add_options" => "_add-options",
17
+ },
18
+ }.freeze
19
+
20
+ @simple_types = [
21
+ String,
22
+ Numeric,
23
+ Integer,
24
+ Float,
25
+ Date,
26
+ Time,
27
+ NilClass,
28
+ ].freeze
29
+
30
+ @document_types = [
31
+ Jekyll::Document,
32
+ Jekyll::Page,
33
+ Jekyll::VERSION.start_with?("2.") ? Jekyll::Post : nil,
34
+ ].compact.freeze
35
+
36
+ def self.document_type?(input)
37
+ @document_types.include?(input.class)
38
+ end
39
+
40
+ def self.simple_type?(input)
41
+ @simple_types.include?(input.class) || [true, false].include?(input)
42
+ end
43
+
44
+ def self.static_file_to_json(input, depth)
45
+ out = [
46
+ "\"extname\": #{JsonifyFilter.to_json(input.extname, depth + 1)}",
47
+ "\"path\": #{JsonifyFilter.to_json(input.relative_path, depth + 1)}",
48
+ ]
49
+
50
+ # modified_time isn't defined in Jekyll 2.4.0
51
+ if input.respond_to? :modified_time
52
+ out.push("\"modified_time\": #{JsonifyFilter.to_json(input.modified_time, depth + 1)}")
53
+ end
54
+
55
+ "{#{out.join(",")}}"
56
+ end
57
+
58
+ def self.document_data_to_json(data, out, prevent, depth)
59
+ prevent += %w(content output next previous excerpt)
60
+
61
+ data.each do |key, value|
62
+ next if prevent.include? key
63
+
64
+ prevent.push key
65
+ out.push("#{key.to_json}: #{JsonifyFilter.to_json(value, depth + 1)}")
66
+ end
67
+
68
+ "{#{out.join(",")}}"
69
+ end
70
+
71
+ def self.legacy_post_to_json(input, depth)
72
+ prevent = %w(dir name path url date id categories tags)
73
+
74
+ out = [
75
+ "\"dir\": #{JsonifyFilter.to_json(input.dir, depth + 1)}",
76
+ "\"name\": #{JsonifyFilter.to_json(input.name, depth + 1)}",
77
+ "\"path\": #{JsonifyFilter.to_json(input.path, depth + 1)}",
78
+ "\"url\": #{JsonifyFilter.to_json(input.url, depth + 1)}",
79
+ "\"date\": #{JsonifyFilter.to_json(input.date, depth + 1)}",
80
+ "\"id\": #{JsonifyFilter.to_json(input.id, depth + 1)}",
81
+ "\"categories\": #{JsonifyFilter.to_json(input.categories, depth + 1)}",
82
+ "\"tags\": #{JsonifyFilter.to_json(input.tags, depth + 1)}",
83
+ ]
84
+
85
+ JsonifyFilter.document_data_to_json(input.data, out, prevent, depth)
86
+ end
87
+
88
+ def self.page_to_json(input, depth)
89
+ prevent = %w(dir name path url)
90
+
91
+ out = [
92
+ "\"dir\": #{JsonifyFilter.to_json(input.dir, depth + 1)}",
93
+ "\"name\": #{JsonifyFilter.to_json(input.name, depth + 1)}",
94
+ "\"path\": #{JsonifyFilter.to_json(input.path, depth + 1)}",
95
+ "\"url\": #{JsonifyFilter.to_json(input.url, depth + 1)}",
96
+ ]
97
+
98
+ # Merge Jekyll Defaults into data for pages (missing at v3.8.5)
99
+ defaults = input.site.frontmatter_defaults.all(input.relative_path, :pages).tap do |h|
100
+ h.delete("date")
101
+ end
102
+
103
+ data = Jekyll::Utils.deep_merge_hashes(defaults, input.data)
104
+ JsonifyFilter.document_data_to_json(data, out, prevent, depth)
105
+ end
106
+
107
+ def self.document_to_json(input, depth)
108
+ prevent = %w(dir id relative_path url collection)
109
+
110
+ out = [
111
+ "\"path\": #{JsonifyFilter.to_json(input.relative_path, depth + 1)}",
112
+ "\"relative_path\": #{JsonifyFilter.to_json(input.relative_path, depth + 1)}",
113
+ "\"url\": #{JsonifyFilter.to_json(input.url, depth + 1)}",
114
+ ]
115
+
116
+ unless input.collection.nil?
117
+ out.push("\"collection\": #{JsonifyFilter.to_json(input.collection.label, depth + 1)}")
118
+ end
119
+
120
+ # id isn't defined in Jekyll 2.4.0
121
+ out.push("\"id\": #{JsonifyFilter.to_json(input.id, depth + 1)}") if input.respond_to? :id
122
+
123
+ JsonifyFilter.document_data_to_json(input.data, out, prevent, depth)
124
+ end
125
+
126
+ def self.array_to_json(input, depth, key_swaps = {})
127
+ array = input.map do |value|
128
+ JsonifyFilter.to_json(value, depth + 1, key_swaps)
129
+ end
130
+
131
+ "[#{array.join(",")}]"
132
+ end
133
+
134
+ def self.hash_to_json(input, depth, key_swaps = {})
135
+ hash = input.map do |key, value|
136
+ "#{(key_swaps[key] || key).to_json}: #{JsonifyFilter.to_json(value, depth + 1, key_swaps)}"
137
+ end
138
+
139
+ "{#{hash.join(",")}}"
140
+ end
141
+
142
+ def self.config_to_select_data_json(input, depth)
143
+ prevent = %w(source destination collections_dir cache_dir plugins_dir layouts_dir data_dir
144
+ includes_dir collections safe include exclude keep_files encoding markdown_ext
145
+ strict_front_matter show_drafts limit_posts future unpublished whitelist
146
+ plugins markdown highlighter lsi excerpt_separator incremental detach port host
147
+ baseurl show_dir_listing permalink paginate_path timezone quiet verbose defaults
148
+ liquid kramdown title url description uploads_dir _comments _options _editor
149
+ _explore _source_editor _array_structures maruku redcloth rdiscount redcarpet
150
+ gems plugins)
151
+
152
+ out = input.map do |key, value|
153
+ next unless value.is_a?(Array) || value.is_a?(Hash)
154
+ next if prevent.include? key
155
+
156
+ prevent.push key
157
+ "#{key.to_json}: #{JsonifyFilter.to_json(value, depth + 1)}"
158
+ end
159
+
160
+ out.compact!
161
+
162
+ "{#{out.join(",")}}" if out.any?
163
+ end
164
+
165
+ def self.to_json(input, depth, key_swaps = {})
166
+ if depth > 8 || (depth > 2 && JsonifyFilter.document_type?(input))
167
+ '"MAXIMUM_DEPTH"'
168
+ elsif JsonifyFilter.simple_type?(input)
169
+ input.to_json
170
+ elsif input.is_a?(Jekyll::StaticFile)
171
+ JsonifyFilter.static_file_to_json(input, depth)
172
+ elsif input.is_a?(Jekyll::Page)
173
+ JsonifyFilter.page_to_json(input, depth)
174
+ elsif Jekyll::VERSION.start_with?("2.") && input.is_a?(Jekyll::Post)
175
+ JsonifyFilter.legacy_post_to_json(input, depth)
176
+ elsif input.is_a?(Jekyll::Document)
177
+ JsonifyFilter.document_to_json(input, depth)
178
+ elsif input.is_a?(Array)
179
+ JsonifyFilter.array_to_json(input, depth, key_swaps)
180
+ elsif input.is_a?(Hash)
181
+ JsonifyFilter.hash_to_json(input, depth, key_swaps)
182
+ else
183
+ input.class.to_s.prepend("UNSUPPORTED:").to_json
184
+ end
185
+ end
186
+
187
+ def cc_static_files_jsonify(input)
188
+ out = []
189
+ input.each do |page|
190
+ next if page.extname != ".html" &&
191
+ page.extname != ".htm" &&
192
+ page.path != "/robots.txt" &&
193
+ page.path != "/sitemap.xml"
194
+
195
+ out.push(JsonifyFilter.to_json(page, 1))
196
+ end
197
+
198
+ "[#{out.join(",")}]"
199
+ end
200
+
201
+ def cc_select_data_jsonify(input)
202
+ if input.key? "_select_data"
203
+ JsonifyFilter.to_json(input["_select_data"], 0)
204
+ else
205
+ JsonifyFilter.config_to_select_data_json(input, 0)
206
+ end
207
+ end
208
+
209
+ def cc_jsonify(input, key_swaps_key = nil)
210
+ if CC_JSONIFY_KEY_SWAPS.key? key_swaps_key
211
+ JsonifyFilter.to_json(input, 0, CC_JSONIFY_KEY_SWAPS[key_swaps_key])
212
+ else
213
+ JsonifyFilter.to_json(input, 0)
214
+ end
215
+ end
216
+ end
217
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CloudCannonJekyll
4
- VERSION = "1.2.3"
4
+ VERSION = "1.4.0"
5
5
  end
@@ -0,0 +1,11 @@
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.8.5 bundle update && $(dirname "$0")/test &&
11
+ JEKYLL_VERSION=4.1.1 bundle update && $(dirname "$0")/test
@@ -2,6 +2,5 @@
2
2
 
3
3
  set -ex
4
4
 
5
- bundle exec rspec "$@"
6
- bundle exec rubocop -S
5
+ $(dirname "$0")/test
7
6
  bundle exec gem build cloudcannon-jekyll.gemspec
@@ -3,3 +3,4 @@
3
3
  set -ex
4
4
 
5
5
  bundle exec rspec "$@"
6
+ bundle exec rubocop -S
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.2.3
4
+ version: 1.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: 2020-09-01 00:00:00.000000000 Z
11
+ date: 2020-09-15 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: '5'
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.13
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.13
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
@@ -126,9 +126,10 @@ files:
126
126
  - lib/cloudcannon-jekyll/_cloudcannon/details.json
127
127
  - lib/cloudcannon-jekyll/configuration.rb
128
128
  - lib/cloudcannon-jekyll/generator.rb
129
+ - lib/cloudcannon-jekyll/jsonify-filter.rb
129
130
  - lib/cloudcannon-jekyll/page-without-a-file.rb
130
- - lib/cloudcannon-jekyll/safe-jsonify-filter.rb
131
131
  - lib/cloudcannon-jekyll/version.rb
132
+ - script/ci-smoke-test
132
133
  - script/cibuild
133
134
  - script/release
134
135
  - script/test
@@ -136,7 +137,7 @@ homepage: https://github.com/cloudcannon/cloudcannon-jekyll
136
137
  licenses:
137
138
  - MIT
138
139
  metadata: {}
139
- post_install_message:
140
+ post_install_message:
140
141
  rdoc_options: []
141
142
  require_paths:
142
143
  - lib
@@ -151,9 +152,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
152
  - !ruby/object:Gem::Version
152
153
  version: '0'
153
154
  requirements: []
154
- rubyforge_project:
155
- rubygems_version: 2.7.6.2
156
- signing_key:
155
+ rubygems_version: 3.0.3
156
+ signing_key:
157
157
  specification_version: 4
158
158
  summary: CloudCannon Jekyll integration
159
159
  test_files: []
@@ -1,215 +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
- ].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.each { |key, value|
49
- next if prevent.include? key
50
- prevent.push key
51
- out.push("#{key.to_json}: #{SafeJsonifyFilter.to_json(value, depth + 1)}")
52
- }
53
-
54
- "{#{out.join(",")}}"
55
- end
56
-
57
- def self.legacy_post_to_json(input, depth)
58
- prevent = %w(dir name path url date id categories tags)
59
-
60
- out = [
61
- "\"dir\": #{SafeJsonifyFilter.to_json(input.dir, depth + 1)}",
62
- "\"name\": #{SafeJsonifyFilter.to_json(input.name, depth + 1)}",
63
- "\"path\": #{SafeJsonifyFilter.to_json(input.path, depth + 1)}",
64
- "\"url\": #{SafeJsonifyFilter.to_json(input.url, depth + 1)}",
65
- "\"date\": #{SafeJsonifyFilter.to_json(input.date, depth + 1)}",
66
- "\"id\": #{SafeJsonifyFilter.to_json(input.id, depth + 1)}",
67
- "\"categories\": #{SafeJsonifyFilter.to_json(input.categories, depth + 1)}",
68
- "\"tags\": #{SafeJsonifyFilter.to_json(input.tags, depth + 1)}",
69
- ]
70
-
71
- SafeJsonifyFilter.document_data_to_json(input.data, out, prevent, depth)
72
- end
73
-
74
- def self.page_to_json(input, depth)
75
- prevent = %w(dir name path url)
76
-
77
- out = [
78
- "\"dir\": #{SafeJsonifyFilter.to_json(input.dir, depth + 1)}",
79
- "\"name\": #{SafeJsonifyFilter.to_json(input.name, depth + 1)}",
80
- "\"path\": #{SafeJsonifyFilter.to_json(input.path, depth + 1)}",
81
- "\"url\": #{SafeJsonifyFilter.to_json(input.url, depth + 1)}",
82
- ]
83
-
84
- # Merge Jekyll Defaults into data for pages (missing at v3.8.5)
85
- defaults = input.site.frontmatter_defaults.all(input.relative_path, :pages).tap do |h|
86
- h.delete("date")
87
- end
88
-
89
- data = Jekyll::Utils.deep_merge_hashes(defaults, input.data)
90
- SafeJsonifyFilter.document_data_to_json(data, out, prevent, depth)
91
- end
92
-
93
- def self.document_to_json(input, depth)
94
- prevent = %w(dir id relative_path url collection)
95
-
96
- out = [
97
- "\"path\": #{SafeJsonifyFilter.to_json(input.relative_path, depth + 1)}",
98
- "\"relative_path\": #{SafeJsonifyFilter.to_json(input.relative_path, depth + 1)}",
99
- "\"url\": #{SafeJsonifyFilter.to_json(input.url, depth + 1)}",
100
- ]
101
-
102
- unless input.collection.nil?
103
- out.push("\"collection\": #{SafeJsonifyFilter.to_json(input.collection.label, depth + 1)}")
104
- end
105
-
106
- # id isn't defined in Jekyll 2.4.0
107
- out.push("\"id\": #{SafeJsonifyFilter.to_json(input.id, depth + 1)}") if input.respond_to? :id
108
-
109
- SafeJsonifyFilter.document_data_to_json(input.data, out, prevent, depth)
110
- end
111
-
112
- def self.array_to_json(input, depth)
113
- array = input.map do |value|
114
- SafeJsonifyFilter.to_json(value, depth + 1)
115
- end
116
-
117
- "[#{array.join(",")}]"
118
- end
119
-
120
- def self.hash_to_json(input, depth)
121
- hash = input.map do |key, value|
122
- "#{key.to_json}: #{SafeJsonifyFilter.to_json(value, depth + 1)}"
123
- end
124
-
125
- "{#{hash.join(",")}}"
126
- end
127
-
128
- def self.site_drop_legacy_select_data_to_json(input, depth)
129
- prevent = %w(config time related_posts destination cache_dir safe
130
- keep_files encoding markdown_ext strict_front_matter show_drafts
131
- limit_posts future unpublished whitelist maruku markdown highlighter
132
- lsi excerpt_separator incremental detach port host show_dir_listing
133
- permalink paginate_path quiet verbose defaults liquid kramdown title
134
- url description categories data tags static_files html_pages pages
135
- documents posts related_posts time source timezone include exclude
136
- baseurl collections _comments _editor _source_editor _explore
137
- uploads_dir plugins_dir data_dir collections_dir includes_dir
138
- layouts_dir _array_structures _options cloudcannon rdiscount redcarpet
139
- redcloth jekyll-archives archives)
140
-
141
- if Jekyll::VERSION.start_with?("2.")
142
- prevent.push "gems"
143
- prevent = prevent.concat input["collections"].keys
144
- elsif Jekyll::VERSION.match?(%r!3\.[0-4]\.!)
145
- prevent.push "gems"
146
- prevent.push "plugins"
147
- prevent = prevent.concat(input["collections"].map { |c| c["label"] })
148
- else
149
- prevent.push "plugins"
150
- prevent = prevent.concat(input.content_methods).uniq
151
- end
152
-
153
- out = []
154
-
155
- input.each_key { |key|
156
- next if prevent.include? key
157
- prevent.push key
158
-
159
- next unless input[key].is_a?(Array) || input[key].is_a?(Hash)
160
-
161
- out << "#{key.to_json}: #{SafeJsonifyFilter.to_json(input[key], depth + 1)}"
162
- }
163
-
164
- "{#{out.join(",")}}" if out.any?
165
- end
166
-
167
- def self.to_json(input, depth)
168
- if depth > 8 || (depth > 2 && SafeJsonifyFilter.document_type?(input))
169
- '"MAXIMUM_DEPTH"'
170
- elsif SafeJsonifyFilter.simple_type?(input)
171
- input.to_json
172
- elsif input.is_a?(Jekyll::StaticFile)
173
- SafeJsonifyFilter.static_file_to_json(input, depth)
174
- elsif input.is_a?(Jekyll::Page)
175
- SafeJsonifyFilter.page_to_json(input, depth)
176
- elsif Jekyll::VERSION.start_with?("2.") && input.is_a?(Jekyll::Post)
177
- SafeJsonifyFilter.legacy_post_to_json(input, depth)
178
- elsif input.is_a?(Jekyll::Document)
179
- SafeJsonifyFilter.document_to_json(input, depth)
180
- elsif input.is_a?(Array)
181
- SafeJsonifyFilter.array_to_json(input, depth)
182
- elsif input.is_a?(Hash)
183
- SafeJsonifyFilter.hash_to_json(input, depth)
184
- else
185
- input.class.to_s.prepend("UNSUPPORTED:").to_json
186
- end
187
- end
188
-
189
- def cc_static_files_jsonify(input)
190
- out = []
191
- input.each do |page|
192
- next if page.extname != ".html" &&
193
- page.extname != ".htm" &&
194
- page.path != "/robots.txt" &&
195
- page.path != "/sitemap.xml"
196
-
197
- out.push(SafeJsonifyFilter.to_json(page, 1))
198
- end
199
-
200
- "[#{out.join(",")}]"
201
- end
202
-
203
- def cc_site_select_data_jsonify(input)
204
- if input.key? "_select_data"
205
- SafeJsonifyFilter.to_json(input["_select_data"], 0)
206
- else
207
- SafeJsonifyFilter.site_drop_legacy_select_data_to_json(input, 0)
208
- end
209
- end
210
-
211
- def cc_safe_jsonify(input)
212
- SafeJsonifyFilter.to_json(input, 0)
213
- end
214
- end
215
- end