cloudcannon-jekyll 2.3.4 → 3.0.0

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
2
  SHA256:
3
- metadata.gz: '09003d2ad672bafc2165e8a667a19c2a730651ddba0fd201904a8575e4c5bba0'
4
- data.tar.gz: 5988731017bdd55c1d2600409ee8e0380847552a79bdc6ef0ff445e810132715
3
+ metadata.gz: 37060b4654f27c7236d0952625b91b56b081c6be24c1a76c034036a80ba1735d
4
+ data.tar.gz: 055c7dbc77a247c254b05bcecedf5a45a9595c0b4ceae671676ec32fa1f771c3
5
5
  SHA512:
6
- metadata.gz: beabc519bea263502f085226ffb98b27d6aa2cd882ca5efe710f63287afaaaeb80f47eea3f118447bbed3d1f89c51c17f6d77134adc5a3f7e11a983ce969e53e
7
- data.tar.gz: d77019b69275bb04a010fa7ce8a0c3763e7a9e1ce449741f62a9e945a5454ffb03fb7395c463cc4434722653156f989a4be81bdac6781bc0efa495c7afc2a2be
6
+ metadata.gz: 4b9536ca8a4097fa234c35a30226a9c17bd9a020e5d883ef82f38883a9a93d6e8f6afbfe17197b949468baec9d6a077f3467ec9b3a23fdaf19740590ce28ba1b
7
+ data.tar.gz: 89bdca52d720c403ddcaf8dc3d20debc1e1da51664874585b132332b199ef444c20c5104686b7ab576b0b5a6ccfad4cabd91157bc38e08a78ca5300e313ea211
data/.gitignore CHANGED
@@ -2,7 +2,6 @@ Gemfile.lock
2
2
  spec/dest/
3
3
  spec/fixtures/**/.jekyll-cache/
4
4
  spec/fixtures/**/.jekyll-metadata
5
- spec/fixtures/_site/
6
5
  gemfiles/.bundle/
7
6
  gemfiles/*.gemfile.lock
8
7
  cloudcannon-jekyll-*.gem
data/.rubocop.yml CHANGED
@@ -1,18 +1,14 @@
1
- require: rubocop-jekyll
2
-
3
- inherit_gem:
4
- rubocop-jekyll: .rubocop.yml
5
-
6
1
  AllCops:
2
+ NewCops: enable
7
3
  TargetRubyVersion: 2.4
8
4
  Include:
9
5
  - lib/**/*.rb
10
-
6
+ - spec/*.rb
11
7
  Exclude:
12
8
  - .gitignore
9
+ - .reek.yml
13
10
  - .rspec
14
11
  - .rubocop.yml
15
- - .travis.yml
16
12
  - Gemfile.lock
17
13
  - HISTORY.md
18
14
  - LICENSE.txt
@@ -20,20 +16,28 @@ AllCops:
20
16
  - script/**/*
21
17
  - vendor/**/*
22
18
  - gemfiles/**/*
23
-
24
- Naming/MemoizedInstanceVariableName:
25
- Exclude:
26
- - lib/cloudcannon-jekyll/page-without-a-file.rb
27
-
28
19
  Metrics/CyclomaticComplexity:
29
- Exclude:
30
- - lib/cloudcannon-jekyll/jsonify-filter.rb # TODO remove this and fix warnings
31
- - lib/cloudcannon-jekyll/readers/old-data-reader.rb # TODO remove this and fix warnings
32
-
20
+ Enabled: false
33
21
  Metrics/PerceivedComplexity:
34
- Exclude:
35
- - lib/cloudcannon-jekyll/jsonify-filter.rb # TODO remove this and fix warnings
36
-
22
+ Enabled: false
37
23
  Metrics/AbcSize:
24
+ Enabled: false
25
+ Metrics/MethodLength:
26
+ Enabled: false
27
+ Metrics/ClassLength:
28
+ Enabled: false
29
+ Layout/LineLength:
30
+ Max: 100
31
+ Naming/FileName:
32
+ Enabled: false
33
+ Style/DoubleNegation:
34
+ Enabled: false
35
+ Metrics/BlockLength:
38
36
  Exclude:
39
- - lib/cloudcannon-jekyll/jsonify-filter.rb # TODO remove this and fix warnings
37
+ - !ruby/regexp /^spec/
38
+ Style/HashEachMethods:
39
+ Enabled: true
40
+ Style/HashTransformKeys:
41
+ Enabled: true
42
+ Style/HashTransformValues:
43
+ Enabled: true
data/HISTORY.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 3.0.0
2
+
3
+ * Add `collections_config_override`
4
+ * Ensure `paths.data` doesnt start with slash
5
+ * Support external configuration files
6
+ * Remove template rendering step and write output directly
7
+ * Update output to support schema version `0.0.3`
8
+
1
9
  # 2.3.4
2
10
 
3
11
  * Add `_editables`
data/README.md CHANGED
@@ -1,47 +1,184 @@
1
- # CloudCannon Jekyll plugin
1
+ # CloudCannon Jekyll
2
2
 
3
- A Jekyll plugin to create CloudCannon editor details.
3
+ A Jekyll plugin that creates [CloudCannon](https://cloudcannon.com/) build information.
4
4
 
5
- [![Build Status](https://travis-ci.com/CloudCannon/cloudcannon-jekyll.svg?branch=main)](https://travis-ci.com/CloudCannon/cloudcannon-jekyll) [![Gem Version](https://badge.fury.io/rb/cloudcannon-jekyll.svg)](https://badge.fury.io/rb/cloudcannon-jekyll)
5
+ This plugin runs during your Jekyll build, discovering your pages, collections, and data files to
6
+ create a JSON file used to automatically integrate the site with CloudCannon.
6
7
 
7
- ## Usage
8
+ [<img src="https://img.shields.io/gem/v/cloudcannon-jekyll?logo=rubygems" alt="version badge">](https://rubygems.org/gems/cloudcannon-jekyll)
9
+ [<img src="https://img.shields.io/gem/dt/cloudcannon-jekyll" alt="downloads badge">](https://rubygems.org/gems/cloudcannon-jekyll)
8
10
 
9
- 1. Add `gem 'cloudcannon-jekyll'` to your site's `Gemfile`
10
- 2. Run `bundle install`
11
- 3. Add the following to your site's `_config.yml`:
11
+ ***
12
+
13
+ - [Installation](#installation)
14
+ - [Configuration](#configuration)
15
+ - [Development](#plugin-options)
16
+ - [License](#license)
17
+
18
+ ***
19
+
20
+ ## Installation
21
+
22
+ **You don't have to install anything** when building on CloudCannon. This plugin is automatically
23
+ installed before your site is built. This gives you the latest support, new features, and fixes
24
+ as they are released.
25
+
26
+ Although **not recommended**, you can install the plugin manually.
27
+
28
+ <details>
29
+ <summary>Manual installation steps</summary>
30
+
31
+ <blockquote>
32
+
33
+ When installing manually, you'll have to upgrade when new versions are released.
34
+ You could also follow these steps to debug an integration issue locally. This assumes you are using [Bundler](https://bundler.io/) to manage dependencies.
35
+
36
+ CloudCannon won't automatically install this plugin before builds if `cloudcannon-jekyll` is already installed.
37
+
38
+ ```sh
39
+ $ bundle add cloudcannon-jekyll --group jekyll_plugins
40
+ ```
41
+
42
+ Add the following to your `_config.yml` if you're listing plugins here as well:
12
43
 
13
44
  ```yaml
14
45
  plugins:
15
46
  - cloudcannon-jekyll
16
47
  ```
17
48
 
18
- 💡 If you are using a Jekyll version less than 3.5.0, use the gems key instead of plugins.
49
+ 💡 For Jekyll versions less than `v3.5.0`, use `gems` instead of `plugins`.
50
+
51
+ </blockquote>
52
+ </details>
53
+
54
+
55
+ ## Configuration
19
56
 
57
+ This plugin uses an optional configuration file as a base to generate `_cloudcannon/info.json`
58
+ (used to integrate your site with CloudCannon).
20
59
 
21
- ## Releasing new version
60
+ Add your global CloudCannon configuration to this file, alongside any optional configuration for
61
+ this plugin.
22
62
 
23
- 1. Increase version in lib/cloudcannon-jekyll/version.rb
24
- 2. Update HISTORY.md
25
- 3. Create a release and tag in GitHub
26
- 4. Build new gem with `gem build cloudcannon-jekyll.gemspec`
27
- 5. Push new version to rubygems.org with `gem push cloudcannon-jekyll-{{ VERSION HERE }}.gem`
63
+ Configuration files should be in the same directory you run `bundle exec jekyll build`. The first
64
+ supported file found in this order is used:
28
65
 
29
- OR:
66
+ - `cloudcannon.config.json`
67
+ - `cloudcannon.config.yaml`
68
+ - `cloudcannon.config.yml`
30
69
 
31
- 1. Increase version in lib/cloudcannon-jekyll/version.rb
32
- 2. Update HISTORY.md
33
- 3. Run `./scripts/release`
34
- 3. Create a release in GitHub
70
+ Alternatively, use the `CLOUDCANNON_CONFIG_PATH` environment variable to use a specific config file
71
+ in a custom location:
35
72
 
73
+ ```sh
74
+ $ CLOUDCANNON_CONFIG_PATH=src/cloudcannon.config.yml bundle exec jekyll build
75
+ ```
36
76
 
37
- ## Testing
77
+ Example content for `cloudcannon.config.yml`:
38
78
 
79
+ ```yaml
80
+ # Global CloudCannon configuration
81
+ _inputs:
82
+ title:
83
+ type: text
84
+ comment: The title of your page.
85
+ _select_data:
86
+ colors:
87
+ - Red
88
+ - Green
89
+ - Blue
90
+
91
+ # Base path to your site source files, same as source for Jekyll
92
+ source: src
93
+
94
+ # The subpath your built output files are mounted at, same as baseurl for Jekyll
95
+ base_url: /documentation
96
+
97
+ # Populates collections for navigation and metadata in the editor
98
+ collections_config:
99
+ people:
100
+ # Base path for files in this collection, relative to source
101
+ path: content/people
102
+
103
+ # Whether this collection produces output files or not
104
+ output: true
105
+
106
+ # Collection-level configuration
107
+ name: Personnel
108
+ _enabled_editors:
109
+ - data
110
+ posts:
111
+ path: _posts
112
+ output: true
113
+ pages:
114
+ name: Main pages
115
+
116
+ # Generates the data for select and multiselect inputs matching these names
117
+ data_config:
118
+ # Populates data with authors from an data file with the matching name
119
+ authors: true
120
+ offices: true
121
+
122
+ paths:
123
+ # The default location for newly uploaded files, relative to source
124
+ uploads: assets/uploads
125
+
126
+ # The path to the root collections folder, relative to source
127
+ collections: items
128
+
129
+ # The path to site data files, relative to source
130
+ data: _data
131
+
132
+ # The path to site layout files, relative to source
133
+ layouts: _layouts
134
+
135
+ # The path to site include files, relative to source
136
+ includes: _partials
39
137
  ```
40
- bundle exec rspec
138
+
139
+ See the [CloudCannon documentation](https://cloudcannon.com/documentation/) for more information
140
+ on the available features you can configure.
141
+
142
+ Configuration is set in `cloudcannon.config.*`, but the plugin also automatically
143
+ reads and processes the following from Jekyll if unset:
144
+
145
+ - `collections_config` from `collections` in `_config.yml`
146
+ - `paths.collections` from `collections_dir` in `_config.yml`
147
+ - `paths.layouts` from `layouts_dir` in `_config.yml`
148
+ - `paths.data` from `data_dir` in `_config.yml`
149
+ - `paths.includes` from `includes_dir` in `_config.yml`
150
+ - `base_url` from `baseurl` in `_config.yml`
151
+ - `source` from the `--source` CLI option or `source` in `_config.yml`
152
+
153
+ ## Development
154
+
155
+ ### Releasing new versions
156
+
157
+ 1. Increase the version in `lib/cloudcannon-jekyll/version.rb`
158
+ 2. Update `HISTORY.md`
159
+ 3. Run `./script/release`
160
+ 3. [Create a release on GitHub](https://github.com/CloudCannon/cloudcannon-jekyll/releases/new)
161
+
162
+ ### Testing
163
+
164
+ Running tests for currently installed Jekyll version:
165
+
166
+ ```sh
167
+ $ ./script/test
41
168
  ```
42
169
 
43
- To test a specific Jekyll version:
170
+ Running tests for all specified Jekyll versions:
44
171
 
172
+ ```sh
173
+ $ ./script/test-all-versions
45
174
  ```
46
- JEKYLL_VERSION="2.4.0" bundle update && bundle exec rspec
175
+
176
+ Running tests for a specific Jekyll version:
177
+
178
+ ```sh
179
+ $ JEKYLL_VERSION="2.4.0" bundle update && ./script/test
47
180
  ```
181
+
182
+ ## License
183
+
184
+ MIT
@@ -1,31 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path("lib", __dir__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
- require "cloudcannon-jekyll/version"
6
+ require 'cloudcannon-jekyll/version'
7
7
 
8
8
  Gem::Specification.new do |spec|
9
- spec.name = "cloudcannon-jekyll"
10
- spec.summary = "CloudCannon Jekyll integration"
11
- spec.description = "Creates CloudCannon editor details for Jekyll"
9
+ spec.name = 'cloudcannon-jekyll'
10
+ spec.summary = 'CloudCannon Jekyll integration'
11
+ spec.description = 'Creates CloudCannon editor details for Jekyll'
12
12
  spec.version = CloudCannonJekyll::VERSION
13
- spec.authors = ["CloudCannon"]
14
- spec.email = ["support@cloudcannon.com"]
15
- spec.homepage = "https://github.com/cloudcannon/cloudcannon-jekyll"
16
- spec.licenses = ["MIT"]
17
- spec.require_paths = ["lib"]
13
+ spec.authors = ['CloudCannon']
14
+ spec.email = ['support@cloudcannon.com']
15
+ spec.homepage = 'https://github.com/cloudcannon/cloudcannon-jekyll'
16
+ spec.licenses = ['MIT']
17
+ spec.require_paths = ['lib']
18
18
 
19
19
  all_files = `git ls-files -z`.split("\x0")
20
- spec.files = all_files.reject { |f| f.match(%r!^(test|spec|features)/!) }
20
+ spec.files = all_files.reject { |f| f.match(%r{^(test|spec|features)/}) }
21
21
 
22
- spec.required_ruby_version = ">= 2.4.0"
22
+ spec.required_ruby_version = '>= 2.4.0'
23
23
 
24
- spec.add_dependency "jekyll", ">= 2.4.0", "< 5"
24
+ spec.add_dependency 'jekyll', '>= 2.4.0'
25
25
 
26
- spec.add_development_dependency "json_schemer", "~> 0.2.13"
27
- spec.add_development_dependency "rake", "~> 13.0"
28
- spec.add_development_dependency "rspec", "~> 3.9"
29
- spec.add_development_dependency "rubocop", "~> 0.80"
30
- spec.add_development_dependency "rubocop-jekyll", "~> 0.11"
26
+ spec.add_development_dependency 'rake', '~> 13.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.9'
28
+ spec.add_development_dependency 'rubocop', '~> 0.80'
31
29
  end
@@ -0,0 +1,146 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+ require 'fileutils'
5
+ require_relative 'logger'
6
+
7
+ module CloudCannonJekyll
8
+ MAPPINGS = {
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
+ '_icon' => 'icon',
17
+ '_add_options' => 'add_options'
18
+ }.freeze
19
+
20
+ # Processes Jekyll configuration to enable the plugin and fix common issues
21
+ class Config
22
+ def self.rename_legacy_collection_config_keys(collection_config)
23
+ collection_config&.keys&.each do |k|
24
+ collection_config[MAPPINGS[k]] = collection_config.delete(k) if MAPPINGS[k]
25
+ end
26
+ end
27
+
28
+ def initialize(site)
29
+ @site_config = site.config
30
+ end
31
+
32
+ def read
33
+ config_defaults(custom_config || config || legacy_config)
34
+ end
35
+
36
+ def custom_config
37
+ custom_path = ENV['CLOUDCANNON_CONFIG_PATH']
38
+ return unless custom_path
39
+
40
+ loaded = config_file(custom_path)
41
+ Logger.info("⚙️ No config file found at #{custom_path.bold}") unless loaded
42
+ loaded
43
+ end
44
+
45
+ def config
46
+ loaded = config_file('cloudcannon.config.json') ||
47
+ config_file('cloudcannon.config.yaml') ||
48
+ config_file('cloudcannon.config.yml')
49
+
50
+ unless loaded
51
+ Logger.info("⚙️ No config file found at #{'cloudcannon.config.(json|yaml|yml)'.bold}")
52
+ end
53
+
54
+ loaded
55
+ end
56
+
57
+ def config_file(path)
58
+ loaded = YAML.safe_load(File.read(path)) # Also works for JSON
59
+ Logger.info "⚙️ Using config file at #{path.bold}"
60
+ loaded
61
+ rescue Errno::ENOENT
62
+ nil
63
+ end
64
+
65
+ def config_defaults(config)
66
+ defaults = {
67
+ 'source' => @site_config['source'].gsub(Dir.pwd, ''),
68
+ 'timezone' => @site_config['timezone'],
69
+ 'base_url' => @site_config['baseurl']
70
+ }
71
+
72
+ defaults.merge(config)
73
+ end
74
+
75
+ def legacy_config
76
+ Logger.info('⚙️ Falling back to site config'.yellow)
77
+
78
+ {
79
+ 'data_config' => @site_config.dig('cloudcannon', 'data'),
80
+ 'collections_config' => legacy_collections_config,
81
+ 'collection_groups' => @site_config['_collection_groups'] || legacy_collection_groups,
82
+ 'editor' => @site_config['_editor'],
83
+ 'source_editor' => @site_config['_source_editor'],
84
+ 'paths' => {
85
+ 'uploads' => @site_config['uploads_dir']
86
+ },
87
+ '_select_data' => @site_config['_select_data'] || legacy_select_data,
88
+ '_inputs' => @site_config['_inputs'],
89
+ '_editables' => @site_config['_editables'],
90
+ '_structures' => @site_config['_structures'],
91
+
92
+ # Deprecated keys
93
+ '_array_structures' => @site_config['_array_structures'],
94
+ '_comments' => @site_config['_comments'],
95
+ '_enabled_editors' => @site_config['_enabled_editors'],
96
+ '_instance_values' => @site_config['_instance_values'],
97
+ '_options' => @site_config['_options']
98
+ }
99
+ end
100
+
101
+ def legacy_collections_config
102
+ collections_config = @site_config.dig('cloudcannon', 'collections')
103
+
104
+ return unless collections_config
105
+
106
+ collections_config.each do |_, collection_config|
107
+ Config.rename_legacy_collection_config_keys(collection_config)
108
+ end
109
+
110
+ collections_config
111
+ end
112
+
113
+ def legacy_collection_groups
114
+ @site_config.dig('_explore', 'groups')
115
+ end
116
+
117
+ def legacy_select_data
118
+ cloudcannon_keys = %w[_comments _options _editor _explore cloudcannon _collection_groups
119
+ _enabled_editors _instance_values _source_editor _array_structures
120
+ uploads_dir _editables _inputs _structures editor source_editor
121
+ collection_groups]
122
+
123
+ jekyll_keys = %w[source destination collections_dir cache_dir plugins_dir layouts_dir
124
+ data_dir includes_dir collections safe include exclude keep_files encoding
125
+ markdown_ext strict_front_matter show_drafts limit_posts future unpublished
126
+ whitelist plugins markdown highlighter lsi excerpt_separator incremental
127
+ detach port host baseurl show_dir_listing permalink paginate_path timezone
128
+ quiet verbose defaults liquid kramdown title url description maruku
129
+ redcloth rdiscount redcarpet gems plugins]
130
+
131
+ keys = cloudcannon_keys + jekyll_keys
132
+
133
+ select_data = @site_config.keys.each_with_object({}) do |key, memo|
134
+ value = @site_config[key]
135
+
136
+ next unless value.is_a?(Array) || value.is_a?(Hash)
137
+ next if key.nil? || keys.include?(key)
138
+
139
+ memo[key] = value
140
+ end
141
+
142
+ compacted = select_data.compact
143
+ compacted.empty? ? nil : compacted
144
+ end
145
+ end
146
+ end