From 3707914d48af9e37aecb116a4668821e4cbc4ea5 Mon Sep 17 00:00:00 2001 From: Ross Phillips Date: Wed, 28 Jul 2021 16:10:55 +1200 Subject: [PATCH] Remove key swaps, increase max depth and add _enabled_editors --- HISTORY.md | 6 +++ .../_cloudcannon/info-2.x.json | 7 +++- .../_cloudcannon/info-3.0-4.x.json | 7 +++- lib/cloudcannon-jekyll/_cloudcannon/info.json | 7 +++- lib/cloudcannon-jekyll/jsonify-filter.rb | 39 ++++++------------- lib/cloudcannon-jekyll/version.rb | 2 +- spec/generator_spec.rb | 14 +++++-- 7 files changed, 44 insertions(+), 38 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index efb239b..41eb287 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,9 @@ +# 2.0.2 + +* Add `_enabled_editors` to global scope +* Increase max jsonify depth +* Remove unused key swaps + # 2.0.1 * Fix potential for null keys in cc_jsonify filter diff --git a/lib/cloudcannon-jekyll/_cloudcannon/info-2.x.json b/lib/cloudcannon-jekyll/_cloudcannon/info-2.x.json index 31ad7dc..80ed881 100644 --- a/lib/cloudcannon-jekyll/_cloudcannon/info-2.x.json +++ b/lib/cloudcannon-jekyll/_cloudcannon/info-2.x.json @@ -17,7 +17,7 @@ {% if config.timezone %} "timezone": {{ config.timezone | cc_jsonify }}, {% endif %} - "collections-config": {{ collections_config | cc_jsonify: 'collections' }}, + "collections-config": {{ collections_config | cc_jsonify }}, "collections": { "drafts": {{ drafts | cc_jsonify }}, "posts": {{ site.posts | reverse | cc_jsonify }}{% if site.collections.size > 0 %},{% endif %} @@ -36,6 +36,9 @@ {% if config._comments %} "_comments": {{ config._comments | cc_jsonify }}, {% endif %} + {% if config._enabled_editors %} + "_enabled_editors": {{ config._enabled_editors | cc_jsonify }}, + {% endif %} {% if config._options %} "_options": {{ config._options | cc_jsonify }}, {% endif %} @@ -63,7 +66,7 @@ "layouts": {{ config.layouts_dir | cc_jsonify }} }, {% if config._array_structures %} - "_array_structures": {{ config._array_structures | cc_jsonify: nil, 50 }}, + "_array_structures": {{ config._array_structures | cc_jsonify: 50 }}, {% endif %} {% assign select_data = config | cc_select_data_jsonify %} {% if select_data %} diff --git a/lib/cloudcannon-jekyll/_cloudcannon/info-3.0-4.x.json b/lib/cloudcannon-jekyll/_cloudcannon/info-3.0-4.x.json index 1cfdf2a..dada234 100644 --- a/lib/cloudcannon-jekyll/_cloudcannon/info-3.0-4.x.json +++ b/lib/cloudcannon-jekyll/_cloudcannon/info-3.0-4.x.json @@ -17,7 +17,7 @@ {% if config.timezone %} "timezone": {{ config.timezone | cc_jsonify }}, {% endif %} - "collections-config": {{ collections_config | cc_jsonify: 'collections' }}, + "collections-config": {{ collections_config | cc_jsonify }}, "collections": { "drafts": {{ drafts | cc_jsonify }}{% if site.collections.size > 0 %},{% endif %} {% for collection in site.collections %}"{{ collection.label | xml_escape }}": {{ collection.docs | cc_jsonify }}{% unless forloop.last %},{% endunless %} @@ -35,6 +35,9 @@ {% if config._comments %} "_comments": {{ config._comments | cc_jsonify }}, {% endif %} + {% if config._enabled_editors %} + "_enabled_editors": {{ config._enabled_editors | cc_jsonify }}, + {% endif %} {% if config._options %} "_options": {{ config._options | cc_jsonify }}, {% endif %} @@ -62,7 +65,7 @@ "layouts": {{ config.layouts_dir | cc_jsonify }} }, {% if config._array_structures %} - "_array_structures": {{ config._array_structures | cc_jsonify: nil, 50 }}, + "_array_structures": {{ config._array_structures | cc_jsonify: 50 }}, {% endif %} {% assign select_data = config | cc_select_data_jsonify %} {% if select_data %} diff --git a/lib/cloudcannon-jekyll/_cloudcannon/info.json b/lib/cloudcannon-jekyll/_cloudcannon/info.json index 0bd6a7b..bcd5eee 100644 --- a/lib/cloudcannon-jekyll/_cloudcannon/info.json +++ b/lib/cloudcannon-jekyll/_cloudcannon/info.json @@ -17,7 +17,7 @@ {% if config.timezone -%} "timezone": {{ config.timezone | cc_jsonify }}, {%- endif %} - "collections-config": {{ collections_config | cc_jsonify: 'collections' }}, + "collections-config": {{ collections_config | cc_jsonify }}, "collections": { "drafts": {{ drafts | cc_jsonify }}{% if site.collections.size > 0 %},{% endif %} {%- for collection in site.collections -%} @@ -48,6 +48,9 @@ {% if config._comments -%} "_comments": {{ config._comments | cc_jsonify }}, {%- endif %} + {% if config._enabled_editors -%} + "_enabled_editors": {{ config._enabled_editors | cc_jsonify }}, + {%- endif %} {% if config._options -%} "_options": {{ config._options | cc_jsonify }}, {%- endif %} @@ -75,7 +78,7 @@ "layouts": {{ config.layouts_dir | cc_jsonify }} }, {% if config._array_structures -%} - "_array_structures": {{ config._array_structures | cc_jsonify: nil, 50 }}, + "_array_structures": {{ config._array_structures | cc_jsonify: 50 }}, {%- endif %} {% assign select_data = config | cc_select_data_jsonify -%} {% if select_data -%} diff --git a/lib/cloudcannon-jekyll/jsonify-filter.rb b/lib/cloudcannon-jekyll/jsonify-filter.rb index 5728f69..04a8657 100644 --- a/lib/cloudcannon-jekyll/jsonify-filter.rb +++ b/lib/cloudcannon-jekyll/jsonify-filter.rb @@ -7,19 +7,6 @@ module CloudCannonJekyll module JsonifyFilter STATIC_EXTENSIONS = [".html", ".htm"].freeze - CC_JSONIFY_KEY_SWAPS = { - "collections" => { - "_sort_key" => "_sort-key", - "_subtext_key" => "_subtext-key", - "_image_key" => "_image-key", - "_image_size" => "_image-size", - "_singular_name" => "_singular-name", - "_singular_key" => "_singular-key", - "_disable_add" => "_disable-add", - "_add_options" => "_add-options", - }, - }.freeze - @simple_types = [ String, Numeric, @@ -137,19 +124,19 @@ def self.document_to_json(input, depth, max_depth) "{#{out.join(",")}}" end - def self.array_to_json(input, depth, max_depth, key_swaps = {}) + def self.array_to_json(input, depth, max_depth) array = input.map do |value| - JsonifyFilter.to_json(value, depth, max_depth, key_swaps) + JsonifyFilter.to_json(value, depth, max_depth) end "[#{array.join(",")}]" end - def self.hash_to_json(input, depth, max_depth, key_swaps = {}) + def self.hash_to_json(input, depth, max_depth) out = input.map do |key, value| next_max_depth = key == "_array_structures" ? 20 : max_depth - string_key = (key_swaps[key] || key).to_s.to_json - "#{string_key}: #{JsonifyFilter.to_json(value, depth, next_max_depth, key_swaps)}" + string_key = key.to_s.to_json + "#{string_key}: #{JsonifyFilter.to_json(value, depth, next_max_depth)}" end "{#{out.join(",")}}" @@ -163,7 +150,7 @@ def self.config_to_select_data_json(input, depth) baseurl show_dir_listing permalink paginate_path timezone quiet verbose defaults liquid kramdown title url description uploads_dir _comments _options _editor _explore _source_editor _array_structures maruku redcloth rdiscount redcarpet - gems plugins cloudcannon _collection_groups) + gems plugins cloudcannon _collection_groups _enabled_editors) out = input.map do |key, value| next unless value.is_a?(Array) || value.is_a?(Hash) @@ -178,7 +165,7 @@ def self.config_to_select_data_json(input, depth) "{#{out.join(",")}}" if out.any? end - def self.to_json(input, depth, max_depth = 9, key_swaps = {}) + def self.to_json(input, depth, max_depth = 12) depth += 1 if depth > max_depth || (depth > 3 && JsonifyFilter.document_type?(input)) @@ -194,9 +181,9 @@ def self.to_json(input, depth, max_depth = 9, key_swaps = {}) elsif input.is_a?(Jekyll::Document) JsonifyFilter.document_to_json(input, depth, max_depth) elsif input.is_a?(Array) - JsonifyFilter.array_to_json(input, depth, max_depth, key_swaps) + JsonifyFilter.array_to_json(input, depth, max_depth) elsif input.is_a?(Hash) - JsonifyFilter.hash_to_json(input, depth, max_depth, key_swaps) + JsonifyFilter.hash_to_json(input, depth, max_depth) else input.class.to_s.prepend("UNSUPPORTED:").to_json end @@ -220,12 +207,8 @@ def cc_select_data_jsonify(input) end end - def cc_jsonify(input, key_swaps_key = nil, max_depth = 8) - if CC_JSONIFY_KEY_SWAPS.key? key_swaps_key - JsonifyFilter.to_json(input, 0, max_depth, CC_JSONIFY_KEY_SWAPS[key_swaps_key]) - else - JsonifyFilter.to_json(input, 0, max_depth) - end + def cc_jsonify(input, max_depth = 12) + JsonifyFilter.to_json(input, 0, max_depth) end end end diff --git a/lib/cloudcannon-jekyll/version.rb b/lib/cloudcannon-jekyll/version.rb index 5c96190..f7a1e3b 100644 --- a/lib/cloudcannon-jekyll/version.rb +++ b/lib/cloudcannon-jekyll/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module CloudCannonJekyll - VERSION = "2.0.1" + VERSION = "2.0.2" end diff --git a/spec/generator_spec.rb b/spec/generator_spec.rb index 38751ac..d80110c 100644 --- a/spec/generator_spec.rb +++ b/spec/generator_spec.rb @@ -319,8 +319,8 @@ expect(staff_members).not_to be_nil expect(staff_members["output"]).to eq(false) expect(staff_members["path"]).to eq("_staff_members") - expect(staff_members["_sort-key"]).to eq("name") - expect(staff_members["_singular-name"]).to eq("staff_member") + expect(staff_members["_sort_key"]).to eq("name") + expect(staff_members["_singular_name"]).to eq("staff_member") empty = collections["empty"] expect(empty).not_to be_nil @@ -468,7 +468,15 @@ "nested2" => { "nested3" => { "nested4" => { - "nested5" => { "nested6" => "MAXIMUM_DEPTH" }, + "nested5" => { + "nested6" => { + "nested7" => { + "nested8" => { + "nested9" => { "nested10" => "MAXIMUM_DEPTH" }, + }, + }, + }, + }, }, }, },