Skip to content

Commit

Permalink
Specify which data keys to include
Browse files Browse the repository at this point in the history
  • Loading branch information
rphillips-nz committed Jul 8, 2020
1 parent c99a5bd commit ac8afab
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ env:
- JEKYLL_VERSION="2.4.0"
- JEKYLL_VERSION="3.0.0"
- JEKYLL_VERSION="3.8.5"
- JEKYLL_VERSION="4.0.0"
- JEKYLL_VERSION="4.1.1"
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.1.0

* Add support for including only specified `data` keys

# 1.0.3

* Fix invalid JSON issue for sites built with Jekyll 2 and no collections
Expand Down
4 changes: 2 additions & 2 deletions cloudcannon-jekyll.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rspec", "~> 3.9"
spec.add_development_dependency "rubocop", "~> 0.71"
spec.add_development_dependency "rubocop-jekyll", "~> 0.10"
spec.add_development_dependency "rubocop", "~> 0.80"
spec.add_development_dependency "rubocop-jekyll", "~> 0.11"
end
6 changes: 4 additions & 2 deletions lib/cloudcannon-jekyll/_cloudcannon/details-2.x.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
"kramdown": {{ site.kramdown | cc_safe_jsonify }},
"commonmark": {{ site.commonmark | cc_safe_jsonify }}
}
},{% if site.cloudcannon.data %}
"data": {{ site.data | cc_safe_jsonify }},{% endif %}
},{% if site.cloudcannon.data.first %}{% assign data_seen = false %}
"data": {
{% 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 %}},
{% elsif site.cloudcannon.data %}"data": {{ site.data | cc_safe_jsonify }},{% endif %}
"collections": {
"posts": {{ site.posts | reverse | cc_safe_jsonify }}{% if site.collections.size > 0 %},{% endif %}
{% for collection in site.collections %}"{{ collection[0] | xml_escape }}": {{ collection[1].docs | cc_safe_jsonify }}{% unless forloop.last %},{% endunless %}
Expand Down
6 changes: 4 additions & 2 deletions lib/cloudcannon-jekyll/_cloudcannon/details-3.0.x.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
"kramdown": {{ site.kramdown | cc_safe_jsonify }},
"commonmark": {{ site.commonmark | cc_safe_jsonify }}
}
},{% if site.cloudcannon.data %}
"data": {{ site.data | cc_safe_jsonify }},{% endif %}
},{% if site.cloudcannon.data.first %}{% assign data_seen = false %}
"data": {
{% 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 %}},
{% elsif site.cloudcannon.data %}"data": {{ site.data | cc_safe_jsonify }},{% endif %}
"collections": {
{% for collection in site.collections %}"{{ collection.label | xml_escape }}": {{ collection.docs | cc_safe_jsonify }}{% unless forloop.last %},{% endunless %}
{% endfor %}
Expand Down
20 changes: 16 additions & 4 deletions lib/cloudcannon-jekyll/_cloudcannon/details.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,26 @@
"commonmark": {{ site.commonmark | cc_safe_jsonify }}
}
},
{%- if site.cloudcannon.data %}
{% if site.cloudcannon.data.first -%}
"data": {
{%- assign data_seen = false %}
{%- 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 -%}
},
{% elsif site.cloudcannon.data -%}
"data": {{ site.data | cc_safe_jsonify }},
{% endif %}
{%- endif %}
"collections": {
{% for collection in site.collections -%}
{%- for collection in site.collections -%}
"{{ collection.label | xml_escape }}": {{ collection.docs | cc_safe_jsonify }}
{%- unless forloop.last %},{% endunless %}
{%- endfor %}
{%- endfor -%}
},
"pages": {{ site.pages | cc_safe_jsonify }},
"static": {{ site.static_files | cc_static_files_jsonify }}
Expand Down
2 changes: 1 addition & 1 deletion lib/cloudcannon-jekyll/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module CloudCannonJekyll
VERSION = "1.0.3"
VERSION = "1.1.0"
end
10 changes: 10 additions & 0 deletions spec/generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,14 @@
end
end
end

context "specific data" do
let(:site_data) { { :cloudcannon => { "data" => { "company" => true } } } }
let(:parsed) { JSON.parse(content) }

it "contains a single data entry" do
expect(parsed["data"].keys.length).to eq(1)
expect(parsed["data"]["company"]).not_to be_nil
end
end
end

0 comments on commit ac8afab

Please sign in to comment.