cloudcannon-jekyll 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 71e33735df4c89f5a837224c14fc5830262d6296
4
- data.tar.gz: 748068f64fd86fb1514533a9b84f8576c7cd79e1
2
+ SHA256:
3
+ metadata.gz: 9ae3c8abe082ec3f37215dec374610ec9afdbcfdf657088948285375e847410f
4
+ data.tar.gz: 44974881ddba3a62062337da11a56d1fbdd406fa04cead477b216866d88bf5cc
5
5
  SHA512:
6
- metadata.gz: '0872a4182a09614927851140c865ad761c5f2ee41c8e79798ad27efc08ef270b1ec9acf60c75da436aea327cf4e11cade050f308921807116fb18e8d8d07fbe5'
7
- data.tar.gz: 6f9207baa8d6084af8a968c2aad4f3d7c9e16e1ec6283408c372e5db156cc890b75e9f22cd98e59619f37172d4981fb859b728f5935d0d3fac40ad17b589ee0e
6
+ metadata.gz: 8d894aea066bba58238ac0a2dbcc277eee56c84d3aeddea107089db51717266f313001d187ac6f5bf077f3f46c044b5842e3e02afa96a0d38fcc8f967889a1c2
7
+ data.tar.gz: f51833d3e91c35ca0e2fa0020b4844a0727c969bf026d01f83922c384ec5b4a0bc68afa11032434a8947281664daf0f5b89f44066d4fb0b76969e8a056486923
@@ -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,13 +20,33 @@ 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
28
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
43
+
29
44
  # This is excluded since the ruby target is 2.3.8 which doesn't support String.match?(Regexp)
30
45
  Performance/RegexpMatch:
31
46
  Exclude:
32
47
  - lib/cloudcannon-jekyll/generator.rb
48
+
49
+ # This is excluded since Jekyll used this and we need to check for it
50
+ Lint/UnifiedInteger:
51
+ Exclude:
52
+ - lib/cloudcannon-jekyll/jsonify-filter.rb
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,10 @@
1
+ # 0.2.1
2
+
3
+ * Add gem information and time to output config file
4
+ * Fix missing in-place compact
5
+ * Fix source being output as full path on disk
6
+ * Read content for output config file directly from site config
7
+
1
8
  # 0.2.0
2
9
 
3
10
  * Add defaults and input-options keys to config output
@@ -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"
@@ -21,9 +21,9 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_dependency "jekyll", ">= 2.4.0", "< 4"
23
23
 
24
+ spec.add_development_dependency "json_schemer", "~> 0.2.4"
24
25
  spec.add_development_dependency "rake", "~> 13.0"
25
26
  spec.add_development_dependency "rspec", "~> 3.9"
26
27
  spec.add_development_dependency "rubocop", "~> 0.80"
27
28
  spec.add_development_dependency "rubocop-jekyll", "~> 0.11"
28
- spec.add_development_dependency "json_schemer", "~> 0.2.4"
29
29
  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,45 +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 | 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._options %}"input-options": {{ site._options | cc_safe_jsonify }},{% endif %}
24
- {% if site.defaults %}"defaults": {{ site.defaults | cc_safe_jsonify }},{% endif %}
25
- {% if site._editor %}"editor": {
26
- "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 %}"comments": {{ 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 }}
27
17
  },{% endif %}
28
- {% if site._source_editor %}"source-editor": {
29
- "tab-size": {{ site._source_editor.tab_size | jsonify }},
30
- "show-gutter": {{ site._source_editor.show_gutter | jsonify }},
31
- "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 }}
32
22
  },{% endif %}
33
- {% if site._explore %}"explore": {{ site._explore | cc_safe_jsonify }},{% endif %}
23
+ {% if config._explore %}"explore": {{ config._explore | cc_jsonify }},{% endif %}
34
24
  "paths": {
35
- "uploads": {{ site.uploads_dir | jsonify }},
36
- "plugins": {{ site.plugins_dir | jsonify }},
37
- "data": {{ site.data_dir | jsonify }},
38
- "collections": {{ site.collections_dir | jsonify }},
39
- "includes": {{ site.includes_dir | jsonify }},
40
- "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 }}
41
31
  },
42
- {% if site._array_structures %}"array-structures": {{ site._array_structures | cc_safe_jsonify }},{% endif %}
43
- {% assign select_data = site | cc_site_select_data_jsonify %}{% if select_data %}"select-data": {{ select_data }},{% endif %}
44
- "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 }}
45
35
  }
@@ -1,45 +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 | 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._options %}"input-options": {{ site._options | cc_safe_jsonify }},{% endif %}
24
- {% if site.defaults %}"defaults": {{ site.defaults | cc_safe_jsonify }},{% endif %}
25
- {% if site._editor %}"editor": {
26
- "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 %}"comments": {{ 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 }}
27
17
  },{% endif %}
28
- {% if site._source_editor %}"source-editor": {
29
- "tab-size": {{ site._source_editor.tab_size | jsonify }},
30
- "show-gutter": {{ site._source_editor.show_gutter | jsonify }},
31
- "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 }}
32
22
  },{% endif %}
33
- {% if site._explore %}"explore": {{ site._explore | cc_safe_jsonify }},{% endif %}
23
+ {% if config._explore %}"explore": {{ config._explore | cc_jsonify }},{% endif %}
34
24
  "paths": {
35
- "uploads": {{ site.uploads_dir | jsonify }},
36
- "plugins": {{ site.plugins_dir | jsonify }},
37
- "data": {{ site.data_dir | jsonify }},
38
- "collections": {{ site.collections_dir | jsonify }},
39
- "includes": {{ site.includes_dir | jsonify }},
40
- "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 }}
41
31
  },
42
- {% if site._array_structures %}"array-structures": {{ site._array_structures | cc_safe_jsonify }},{% endif %}
43
- {% assign select_data = site | cc_site_select_data_jsonify %}{% if select_data %}"select-data": {{ select_data }},{% endif %}
44
- "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 }}
45
35
  }
@@ -1,67 +1,58 @@
1
1
  {
2
- {% if site.timezone -%}
3
- "timezone": {{ site.timezone | jsonify }},
2
+ "time": {{ site.time | cc_jsonify }},
3
+ "cloudcannon": {
4
+ "name": "cloudcannon-jekyll",
5
+ "version": {{ gem_version | cc_jsonify }}
6
+ },
7
+ {% if config.timezone -%}
8
+ "timezone": {{ config.timezone | cc_jsonify }},
4
9
  {%- endif %}
5
- "include": {{ site.include | jsonify }},
6
- "exclude": {{ site.exclude | jsonify }},
7
- {% if site.baseurl -%}
8
- "base-url": {{ site.baseurl | jsonify }},
10
+ "include": {{ config.include | cc_jsonify }},
11
+ "exclude": {{ config.exclude | cc_jsonify }},
12
+ {% if config.baseurl -%}
13
+ "base-url": {{ config.baseurl | cc_jsonify }},
9
14
  {%- 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 -%}
26
- },
27
- {% if site._comments -%}
28
- "comments": {{ site._comments | cc_safe_jsonify }},
15
+ {% if config.collections -%}
16
+ "collections": {{ config.collections | cc_jsonify: 'collections' }},
17
+ {%- endif %}
18
+ {% if config._comments -%}
19
+ "comments": {{ config._comments | cc_jsonify }},
29
20
  {%- endif %}
30
- {% if site._options -%}
31
- "input-options": {{ site._options | cc_safe_jsonify }},
21
+ {% if config._options -%}
22
+ "input-options": {{ config._options | cc_jsonify }},
32
23
  {%- endif %}
33
- {% if site.defaults -%}
34
- "defaults": {{ site.defaults | cc_safe_jsonify }},
24
+ {% if config.defaults -%}
25
+ "defaults": {{ config.defaults | cc_jsonify }},
35
26
  {%- endif %}
36
- {% if site._editor -%}
27
+ {% if config._editor -%}
37
28
  "editor": {
38
- "default-path": {{ site._editor.default_path | jsonify }}
29
+ "default-path": {{ config._editor.default_path | cc_jsonify }}
39
30
  },
40
31
  {%- endif %}
41
- {% if site._source_editor -%}
32
+ {% if config._source_editor -%}
42
33
  "source-editor": {
43
- "tab-size": {{ site._source_editor.tab_size | jsonify }},
44
- "show-gutter": {{ site._source_editor.show_gutter | jsonify }},
45
- "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 }}
46
37
  },
47
38
  {%- endif %}
48
- {% if site._explore -%}
49
- "explore": {{ site._explore | cc_safe_jsonify }},
39
+ {% if config._explore -%}
40
+ "explore": {{ config._explore | cc_jsonify }},
50
41
  {%- endif %}
51
42
  "paths": {
52
- "uploads": {{ site.uploads_dir | jsonify }},
53
- "plugins": {{ site.plugins_dir | jsonify }},
54
- "data": {{ site.data_dir | jsonify }},
55
- "collections": {{ site.collections_dir | jsonify }},
56
- "includes": {{ site.includes_dir | jsonify }},
57
- "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 }}
58
49
  },
59
- {% if site._array_structures -%}
60
- "array-structures": {{ site._array_structures | cc_safe_jsonify }},
50
+ {% if config._array_structures -%}
51
+ "array-structures": {{ config._array_structures | cc_jsonify }},
61
52
  {%- endif %}
62
- {% assign select_data = site | cc_site_select_data_jsonify -%}
53
+ {% assign select_data = config | cc_select_data_jsonify -%}
63
54
  {% if select_data -%}
64
55
  "select-data": {{ select_data }},
65
56
  {%- endif %}
66
- "source": {{ site.source | jsonify }}
57
+ "source": {{ config.source | replace: pwd, "" | cc_jsonify }}
67
58
  }
@@ -1,27 +1,27 @@
1
1
  {
2
- "time": {{ site.time | jsonify }},
2
+ "time": {{ site.time | 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 | 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 | 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,218 @@
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
+ Object.const_defined?("Fixnum") ? Fixnum : nil,
29
+ ].compact.freeze
30
+
31
+ @document_types = [
32
+ Jekyll::Document,
33
+ Jekyll::Page,
34
+ Jekyll::VERSION.start_with?("2.") ? Jekyll::Post : nil,
35
+ ].compact.freeze
36
+
37
+ def self.document_type?(input)
38
+ @document_types.include?(input.class)
39
+ end
40
+
41
+ def self.simple_type?(input)
42
+ @simple_types.include?(input.class) || [true, false].include?(input)
43
+ end
44
+
45
+ def self.static_file_to_json(input, depth)
46
+ out = [
47
+ "\"extname\": #{JsonifyFilter.to_json(input.extname, depth + 1)}",
48
+ "\"path\": #{JsonifyFilter.to_json(input.relative_path, depth + 1)}",
49
+ ]
50
+
51
+ # modified_time isn't defined in Jekyll 2.4.0
52
+ if input.respond_to? :modified_time
53
+ out.push("\"modified_time\": #{JsonifyFilter.to_json(input.modified_time, depth + 1)}")
54
+ end
55
+
56
+ "{#{out.join(",")}}"
57
+ end
58
+
59
+ def self.document_data_to_json(data, out, prevent, depth)
60
+ prevent += %w(content output next previous excerpt)
61
+
62
+ data.each do |key, value|
63
+ next if prevent.include? key
64
+
65
+ prevent.push key
66
+ out.push("#{key.to_json}: #{JsonifyFilter.to_json(value, depth + 1)}")
67
+ end
68
+
69
+ "{#{out.join(",")}}"
70
+ end
71
+
72
+ def self.legacy_post_to_json(input, depth)
73
+ prevent = %w(dir name path url date id categories tags)
74
+
75
+ out = [
76
+ "\"dir\": #{JsonifyFilter.to_json(input.dir, depth + 1)}",
77
+ "\"name\": #{JsonifyFilter.to_json(input.name, depth + 1)}",
78
+ "\"path\": #{JsonifyFilter.to_json(input.path, depth + 1)}",
79
+ "\"url\": #{JsonifyFilter.to_json(input.url, depth + 1)}",
80
+ "\"date\": #{JsonifyFilter.to_json(input.date, depth + 1)}",
81
+ "\"id\": #{JsonifyFilter.to_json(input.id, depth + 1)}",
82
+ "\"categories\": #{JsonifyFilter.to_json(input.categories, depth + 1)}",
83
+ "\"tags\": #{JsonifyFilter.to_json(input.tags, depth + 1)}",
84
+ ]
85
+
86
+ JsonifyFilter.document_data_to_json(input.data, out, prevent, depth)
87
+ end
88
+
89
+ def self.page_to_json(input, depth)
90
+ prevent = %w(dir name path url)
91
+
92
+ out = [
93
+ "\"dir\": #{JsonifyFilter.to_json(input.dir, depth + 1)}",
94
+ "\"name\": #{JsonifyFilter.to_json(input.name, depth + 1)}",
95
+ "\"path\": #{JsonifyFilter.to_json(input.path, depth + 1)}",
96
+ "\"url\": #{JsonifyFilter.to_json(input.url, depth + 1)}",
97
+ ]
98
+
99
+ # Merge Jekyll Defaults into data for pages (missing at v3.8.5)
100
+ defaults = input.site.frontmatter_defaults.all(input.relative_path, :pages).tap do |h|
101
+ h.delete("date")
102
+ end
103
+
104
+ data = Jekyll::Utils.deep_merge_hashes(defaults, input.data)
105
+ JsonifyFilter.document_data_to_json(data, out, prevent, depth)
106
+ end
107
+
108
+ def self.document_to_json(input, depth)
109
+ prevent = %w(dir id relative_path url collection)
110
+
111
+ out = [
112
+ "\"path\": #{JsonifyFilter.to_json(input.relative_path, depth + 1)}",
113
+ "\"relative_path\": #{JsonifyFilter.to_json(input.relative_path, depth + 1)}",
114
+ "\"url\": #{JsonifyFilter.to_json(input.url, depth + 1)}",
115
+ ]
116
+
117
+ unless input.collection.nil?
118
+ out.push("\"collection\": #{JsonifyFilter.to_json(input.collection.label, depth + 1)}")
119
+ end
120
+
121
+ # id isn't defined in Jekyll 2.4.0
122
+ out.push("\"id\": #{JsonifyFilter.to_json(input.id, depth + 1)}") if input.respond_to? :id
123
+
124
+ JsonifyFilter.document_data_to_json(input.data, out, prevent, depth)
125
+ end
126
+
127
+ def self.array_to_json(input, depth, key_swaps = {})
128
+ array = input.map do |value|
129
+ JsonifyFilter.to_json(value, depth + 1, key_swaps)
130
+ end
131
+
132
+ "[#{array.join(",")}]"
133
+ end
134
+
135
+ def self.hash_to_json(input, depth, key_swaps = {})
136
+ hash = input.map do |key, value|
137
+ "#{(key_swaps[key] || key).to_json}: #{JsonifyFilter.to_json(value, depth + 1, key_swaps)}"
138
+ end
139
+
140
+ "{#{hash.join(",")}}"
141
+ end
142
+
143
+ def self.config_to_select_data_json(input, depth)
144
+ prevent = %w(source destination collections_dir cache_dir plugins_dir layouts_dir data_dir
145
+ includes_dir collections safe include exclude keep_files encoding markdown_ext
146
+ strict_front_matter show_drafts limit_posts future unpublished whitelist
147
+ plugins markdown highlighter lsi excerpt_separator incremental detach port host
148
+ baseurl show_dir_listing permalink paginate_path timezone quiet verbose defaults
149
+ liquid kramdown title url description uploads_dir _comments _options _editor
150
+ _explore _source_editor _array_structures maruku redcloth rdiscount redcarpet
151
+ gems plugins)
152
+
153
+ out = input.map do |key, value|
154
+ next unless value.is_a?(Array) || value.is_a?(Hash)
155
+ next if prevent.include? key
156
+
157
+ prevent.push key
158
+ "#{key.to_json}: #{JsonifyFilter.to_json(value, depth + 1)}"
159
+ end
160
+
161
+ out.compact!
162
+
163
+ "{#{out.join(",")}}" if out.any?
164
+ end
165
+
166
+ def self.to_json(input, depth, key_swaps = {})
167
+ if depth > 8 || (depth > 2 && JsonifyFilter.document_type?(input))
168
+ '"MAXIMUM_DEPTH"'
169
+ elsif JsonifyFilter.simple_type?(input)
170
+ input.to_json
171
+ elsif input.is_a?(Jekyll::StaticFile)
172
+ JsonifyFilter.static_file_to_json(input, depth)
173
+ elsif input.is_a?(Jekyll::Page)
174
+ JsonifyFilter.page_to_json(input, depth)
175
+ elsif Jekyll::VERSION.start_with?("2.") && input.is_a?(Jekyll::Post)
176
+ JsonifyFilter.legacy_post_to_json(input, depth)
177
+ elsif input.is_a?(Jekyll::Document)
178
+ JsonifyFilter.document_to_json(input, depth)
179
+ elsif input.is_a?(Array)
180
+ JsonifyFilter.array_to_json(input, depth, key_swaps)
181
+ elsif input.is_a?(Hash)
182
+ JsonifyFilter.hash_to_json(input, depth, key_swaps)
183
+ else
184
+ input.class.to_s.prepend("UNSUPPORTED:").to_json
185
+ end
186
+ end
187
+
188
+ def cc_static_files_jsonify(input)
189
+ out = []
190
+ input.each do |page|
191
+ next if page.extname != ".html" &&
192
+ page.extname != ".htm" &&
193
+ page.path != "/robots.txt" &&
194
+ page.path != "/sitemap.xml"
195
+
196
+ out.push(JsonifyFilter.to_json(page, 1))
197
+ end
198
+
199
+ "[#{out.join(",")}]"
200
+ end
201
+
202
+ def cc_select_data_jsonify(input)
203
+ if input.key? "_select_data"
204
+ JsonifyFilter.to_json(input["_select_data"], 0)
205
+ else
206
+ JsonifyFilter.config_to_select_data_json(input, 0)
207
+ end
208
+ end
209
+
210
+ def cc_jsonify(input, key_swaps_key = nil)
211
+ if CC_JSONIFY_KEY_SWAPS.key? key_swaps_key
212
+ JsonifyFilter.to_json(input, 0, CC_JSONIFY_KEY_SWAPS[key_swaps_key])
213
+ else
214
+ JsonifyFilter.to_json(input, 0)
215
+ end
216
+ end
217
+ end
218
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CloudCannonJekyll
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  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
@@ -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: 0.2.0
4
+ version: 0.2.1
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-14 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.4
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.4
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.5.2.3
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,216 +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 _options cloudcannon rdiscount redcarpet
140
- redcloth jekyll-archives archives)
141
-
142
- if Jekyll::VERSION.start_with?("2.")
143
- prevent.push "gems"
144
- prevent = prevent.concat input["collections"].keys
145
- elsif %r!3\.[0-4]\.! =~ Jekyll::VERSION
146
- prevent.push "gems"
147
- prevent.push "plugins"
148
- prevent = prevent.concat(input["collections"].map { |c| c["label"] })
149
- else
150
- prevent.push "plugins"
151
- prevent = prevent.concat(input.content_methods).uniq
152
- end
153
-
154
- out = []
155
-
156
- input.each_key { |key|
157
- next if prevent.include? key
158
- prevent.push key
159
-
160
- next unless input[key].is_a?(Array) || input[key].is_a?(Hash)
161
-
162
- out << "#{key.to_json}: #{SafeJsonifyFilter.to_json(input[key], depth + 1)}"
163
- }
164
-
165
- "{#{out.join(",")}}" if out.any?
166
- end
167
-
168
- def self.to_json(input, depth)
169
- if depth > 8 || (depth > 2 && SafeJsonifyFilter.document_type?(input))
170
- '"MAXIMUM_DEPTH"'
171
- elsif SafeJsonifyFilter.simple_type?(input)
172
- input.to_json
173
- elsif input.is_a?(Jekyll::StaticFile)
174
- SafeJsonifyFilter.static_file_to_json(input, depth)
175
- elsif input.is_a?(Jekyll::Page)
176
- SafeJsonifyFilter.page_to_json(input, depth)
177
- elsif Jekyll::VERSION.start_with?("2.") && input.is_a?(Jekyll::Post)
178
- SafeJsonifyFilter.legacy_post_to_json(input, depth)
179
- elsif input.is_a?(Jekyll::Document)
180
- SafeJsonifyFilter.document_to_json(input, depth)
181
- elsif input.is_a?(Array)
182
- SafeJsonifyFilter.array_to_json(input, depth)
183
- elsif input.is_a?(Hash)
184
- SafeJsonifyFilter.hash_to_json(input, depth)
185
- else
186
- input.class.to_s.prepend("UNSUPPORTED:").to_json
187
- end
188
- end
189
-
190
- def cc_static_files_jsonify(input)
191
- out = []
192
- input.each do |page|
193
- next if page.extname != ".html" &&
194
- page.extname != ".htm" &&
195
- page.path != "/robots.txt" &&
196
- page.path != "/sitemap.xml"
197
-
198
- out.push(SafeJsonifyFilter.to_json(page, 1))
199
- end
200
-
201
- "[#{out.join(",")}]"
202
- end
203
-
204
- def cc_site_select_data_jsonify(input)
205
- if input.key? "_select_data"
206
- SafeJsonifyFilter.to_json(input["_select_data"], 0)
207
- else
208
- SafeJsonifyFilter.site_drop_legacy_select_data_to_json(input, 0)
209
- end
210
- end
211
-
212
- def cc_safe_jsonify(input)
213
- SafeJsonifyFilter.to_json(input, 0)
214
- end
215
- end
216
- end