cloudcannon-jekyll 0.3.4 → 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.
@@ -1,27 +0,0 @@
1
- {
2
- "time": {{ site.time | date_to_xmlschema | cc_jsonify }},
3
- "cloudcannon": {
4
- "name": "cloudcannon-jekyll",
5
- "version": {{ gem_version | cc_jsonify }}
6
- },
7
- "generator": {
8
- "name": "jekyll",
9
- "version": {{ jekyll.version | cc_jsonify }},
10
- "environment": {{ jekyll.env | cc_jsonify }},
11
- "metadata": {
12
- "markdown": {{ site.markdown | cc_jsonify }},
13
- "kramdown": {{ site.kramdown | cc_jsonify }},
14
- "commonmark": {{ site.commonmark | cc_jsonify }}
15
- }
16
- },{% if site.cloudcannon.data.first %}{% assign data_seen = false %}
17
- "data": {
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
- "collections": {
21
- "drafts": {{ drafts | cc_jsonify }}{% if site.collections.size > 0 %},{% endif %}
22
- {% for collection in site.collections %}"{{ collection.label | xml_escape }}": {{ collection.docs | cc_jsonify }}{% unless forloop.last %},{% endunless %}
23
- {% endfor %}
24
- },
25
- "pages": {{ site.pages | cc_jsonify }},
26
- "static-pages": {{ site.static_files | cc_static_files_jsonify }}
27
- }
@@ -1,222 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "jekyll"
4
-
5
- module CloudCannonJekyll
6
- # Filter for converting Jekyll objects into JSON
7
- module JsonifyFilter
8
- STATIC_EXTENSIONS = [".html", ".htm"].freeze
9
-
10
- CC_JSONIFY_KEY_SWAPS = {
11
- "collections" => {
12
- "_sort_key" => "_sort-key",
13
- "_subtext_key" => "_subtext-key",
14
- "_image_key" => "_image-key",
15
- "_image_size" => "_image-size",
16
- "_singular_name" => "_singular-name",
17
- "_singular_key" => "_singular-key",
18
- "_disable_add" => "_disable-add",
19
- "_add_options" => "_add-options",
20
- },
21
- }.freeze
22
-
23
- @simple_types = [
24
- String,
25
- Numeric,
26
- Integer,
27
- Float,
28
- Date,
29
- Time,
30
- NilClass,
31
- Object.const_defined?("Fixnum") ? Fixnum : nil,
32
- ].compact.freeze
33
-
34
- @document_types = [
35
- Jekyll::Document,
36
- Jekyll::Page,
37
- Jekyll::VERSION.start_with?("2.") ? Jekyll::Post : nil,
38
- ].compact.freeze
39
-
40
- def self.document_type?(input)
41
- @document_types.include?(input.class)
42
- end
43
-
44
- def self.simple_type?(input)
45
- @simple_types.include?(input.class) || [true, false].include?(input)
46
- end
47
-
48
- def self.static_file_to_json(input, depth, max_depth)
49
- path = input.relative_path.sub(%r!^\/+!, "")
50
- url = Jekyll::VERSION.start_with?("2.") ? "/#{path}" : input.url
51
-
52
- out = [
53
- "\"path\": #{JsonifyFilter.to_json(path, depth, max_depth)}",
54
- "\"url\": #{JsonifyFilter.to_json(url, depth, max_depth)}",
55
- ]
56
-
57
- "{#{out.join(",")}}"
58
- end
59
-
60
- def self.document_data_to_a(data, prevent, depth, max_depth)
61
- prevent += %w(content output next previous excerpt)
62
-
63
- out = data.map do |key, value|
64
- next if prevent.include? key
65
-
66
- prevent.push key
67
- "#{key.to_json}: #{JsonifyFilter.to_json(value, depth, max_depth)}"
68
- end
69
-
70
- out.compact
71
- end
72
-
73
- def self.legacy_post_to_json(input, depth, max_depth)
74
- prevent = %w(dir name path url date id categories tags)
75
-
76
- out = [
77
- "\"name\": #{JsonifyFilter.to_json(input.name, depth, max_depth)}",
78
- "\"path\": #{JsonifyFilter.to_json(input.path, depth, max_depth)}",
79
- "\"url\": #{JsonifyFilter.to_json(input.url, depth, max_depth)}",
80
- "\"date\": #{JsonifyFilter.to_json(input.date, depth, max_depth)}",
81
- "\"id\": #{JsonifyFilter.to_json(input.id, depth, max_depth)}",
82
- "\"categories\": #{JsonifyFilter.to_json(input.categories, depth, max_depth)}",
83
- "\"tags\": #{JsonifyFilter.to_json(input.tags, depth, max_depth)}",
84
- ]
85
-
86
- out += JsonifyFilter.document_data_to_a(input.data, prevent, depth, max_depth)
87
- "{#{out.join(",")}}"
88
- end
89
-
90
- def self.page_to_json(input, depth, max_depth)
91
- prevent = %w(dir name path url)
92
-
93
- out = [
94
- "\"name\": #{JsonifyFilter.to_json(input.name, depth, max_depth)}",
95
- "\"path\": #{JsonifyFilter.to_json(input.path, depth, max_depth)}",
96
- "\"url\": #{JsonifyFilter.to_json(input.url, depth, max_depth)}",
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 |default|
101
- default.delete("date")
102
- end
103
-
104
- data = Jekyll::Utils.deep_merge_hashes(defaults, input.data)
105
-
106
- out += JsonifyFilter.document_data_to_a(data, prevent, depth, max_depth)
107
- "{#{out.join(",")}}"
108
- end
109
-
110
- def self.document_to_json(input, depth, max_depth)
111
- prevent = %w(dir relative_path url collection)
112
-
113
- out = [
114
- "\"path\": #{JsonifyFilter.to_json(input.relative_path, depth, max_depth)}",
115
- "\"url\": #{JsonifyFilter.to_json(input.url, depth, max_depth)}",
116
- ]
117
-
118
- collection = input.collection
119
- unless collection.nil?
120
- collection_json = JsonifyFilter.to_json(collection.label, depth, max_depth)
121
- out.push("\"collection\": #{collection_json}")
122
- end
123
-
124
- if input.respond_to? :id
125
- out.push("\"id\": #{JsonifyFilter.to_json(input.id, depth, max_depth)}")
126
- end
127
-
128
- out += JsonifyFilter.document_data_to_a(input.data, prevent, depth, max_depth)
129
- "{#{out.join(",")}}"
130
- end
131
-
132
- def self.array_to_json(input, depth, max_depth, key_swaps = {})
133
- array = input.map do |value|
134
- JsonifyFilter.to_json(value, depth, max_depth, key_swaps)
135
- end
136
-
137
- "[#{array.join(",")}]"
138
- end
139
-
140
- def self.hash_to_json(input, depth, max_depth, key_swaps = {})
141
- out = input.map do |key, value|
142
- string_key = (key_swaps[key] || key).to_s.to_json
143
- "#{string_key}: #{JsonifyFilter.to_json(value, depth, max_depth, key_swaps)}"
144
- end
145
-
146
- "{#{out.join(",")}}"
147
- end
148
-
149
- def self.config_to_select_data_json(input, depth)
150
- prevent = %w(source destination collections_dir cache_dir plugins_dir layouts_dir data_dir
151
- includes_dir collections safe include exclude keep_files encoding markdown_ext
152
- strict_front_matter show_drafts limit_posts future unpublished whitelist
153
- plugins markdown highlighter lsi excerpt_separator incremental detach port host
154
- baseurl show_dir_listing permalink paginate_path timezone quiet verbose defaults
155
- liquid kramdown title url description uploads_dir _comments _options _editor
156
- _explore _source_editor _array_structures maruku redcloth rdiscount redcarpet
157
- gems plugins)
158
-
159
- out = input.map do |key, value|
160
- next unless value.is_a?(Array) || value.is_a?(Hash)
161
- next if prevent.include? key
162
-
163
- prevent.push key
164
- "#{key.to_s.to_json}: #{JsonifyFilter.to_json(value, depth)}"
165
- end
166
-
167
- out.compact!
168
-
169
- "{#{out.join(",")}}" if out.any?
170
- end
171
-
172
- def self.to_json(input, depth, max_depth = 9, key_swaps = {})
173
- depth += 1
174
-
175
- if depth > max_depth || (depth > 3 && JsonifyFilter.document_type?(input))
176
- '"MAXIMUM_DEPTH"'
177
- elsif JsonifyFilter.simple_type?(input)
178
- input.to_json
179
- elsif input.is_a?(Jekyll::StaticFile)
180
- JsonifyFilter.static_file_to_json(input, depth, max_depth)
181
- elsif input.is_a?(Jekyll::Page)
182
- JsonifyFilter.page_to_json(input, depth, max_depth)
183
- elsif Jekyll::VERSION.start_with?("2.") && input.is_a?(Jekyll::Post)
184
- JsonifyFilter.legacy_post_to_json(input, depth, max_depth)
185
- elsif input.is_a?(Jekyll::Document)
186
- JsonifyFilter.document_to_json(input, depth, max_depth)
187
- elsif input.is_a?(Array)
188
- JsonifyFilter.array_to_json(input, depth, max_depth, key_swaps)
189
- elsif input.is_a?(Hash)
190
- JsonifyFilter.hash_to_json(input, depth, max_depth, key_swaps)
191
- else
192
- input.class.to_s.prepend("UNSUPPORTED:").to_json
193
- end
194
- end
195
-
196
- def cc_static_files_jsonify(input)
197
- out = input.map do |page|
198
- JsonifyFilter.to_json(page, 1) if STATIC_EXTENSIONS.include?(page.extname)
199
- end
200
-
201
- out.compact!
202
-
203
- "[#{out.join(",")}]"
204
- end
205
-
206
- def cc_select_data_jsonify(input)
207
- if input.key? "_select_data"
208
- JsonifyFilter.to_json(input["_select_data"], 0)
209
- else
210
- JsonifyFilter.config_to_select_data_json(input, 0)
211
- end
212
- end
213
-
214
- def cc_jsonify(input, key_swaps_key = nil, max_depth = 8)
215
- if CC_JSONIFY_KEY_SWAPS.key? key_swaps_key
216
- JsonifyFilter.to_json(input, 0, max_depth, CC_JSONIFY_KEY_SWAPS[key_swaps_key])
217
- else
218
- JsonifyFilter.to_json(input, 0, max_depth)
219
- end
220
- end
221
- end
222
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "jekyll"
4
- require_relative "readers/old-data-reader"
5
- require_relative "readers/data-reader"
6
-
7
- module CloudCannonJekyll
8
- # Wraps read functions into one class
9
- class Reader
10
- attr_reader :site
11
-
12
- def initialize(site)
13
- @site = site
14
- end
15
-
16
- def read_data(dir = "_data")
17
- # DataReader doesn't exist in old versions of Jekyll
18
- if Jekyll::VERSION.start_with? "2."
19
- CloudCannonJekyll::OldDataReader.new(@site).read(dir)
20
- else
21
- CloudCannonJekyll::DataReader.new(@site).read(dir)
22
- end
23
- end
24
-
25
- def read_drafts(dir = "")
26
- # PostReader doesn't exist in old versions of Jekyll
27
- if Jekyll::VERSION.start_with? "2."
28
- @site.read_content(dir, "_drafts", Jekyll::Draft)
29
- else
30
- Jekyll::PostReader.new(@site).read_drafts(dir)
31
- end
32
- end
33
-
34
- def read_posts(dir = "")
35
- # PostReader doesn't exist in old versions of Jekyll
36
- if Jekyll::VERSION.start_with? "2."
37
- @site.read_content(dir, "_posts", Jekyll::Post)
38
- else
39
- Jekyll::PostReader.new(@site).read_posts(dir)
40
- end
41
- end
42
- end
43
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- unless Jekyll::VERSION.start_with? "2."
4
- require "jekyll"
5
-
6
- module CloudCannonJekyll
7
- # Reads data files and creates a collections-style hash representation
8
- class DataReader < Jekyll::DataReader
9
- # Determines how to read a data file.
10
- # This is overridden return a hash instead of reading the file.
11
- #
12
- # Returns a hash with the path to the data file.
13
- def read_data_file(path)
14
- {
15
- "path" => path,
16
- }
17
- end
18
- end
19
- end
20
- end
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- if Jekyll::VERSION.start_with? "2."
4
- require "jekyll"
5
-
6
- module CloudCannonJekyll
7
- # Reads data files and creates a collections-style hash representation
8
- # Aims to replicate the data reading logic in Jekyll 2.5
9
- class OldDataReader
10
- attr_reader :site
11
-
12
- def initialize(site)
13
- @site = site
14
- @safe = site.safe
15
- @content = {}
16
- end
17
-
18
- def read(dir)
19
- base = Jekyll.sanitized_path(@site.source, dir)
20
- read_data_to(base, @content)
21
- @content
22
- end
23
-
24
- def read_data_to(dir, data)
25
- return unless File.directory?(dir) && (!@safe || !File.symlink?(dir))
26
-
27
- entries = Dir.chdir(dir) do
28
- Dir["*.{yaml,yml,json,csv}"] + Dir["*"].select { |fn| File.directory?(fn) }
29
- end
30
-
31
- entries.each do |entry|
32
- path = Jekyll.sanitized_path(dir, entry)
33
- next if File.symlink?(path) && @safe
34
-
35
- key = sanitize_filename(File.basename(entry, ".*"))
36
- if File.directory?(path)
37
- read_data_to(path, data[key] = {})
38
- else
39
- data[key] = read_data_file(path)
40
- end
41
- end
42
- end
43
-
44
- def read_data_file(path)
45
- {
46
- "path" => path,
47
- }
48
- end
49
-
50
- def sanitize_filename(name)
51
- name.gsub!(%r![^\w\s_-]+!, "")
52
- name.gsub!(%r!(^|\b\s)\s+($|\s?\b)!, '\\1\\2')
53
- name.gsub(%r!\s+!, "_")
54
- end
55
- end
56
- end
57
- end
@@ -1,10 +0,0 @@
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