Skip to content

Commit

Permalink
feat: automatically set the array structure id_key for components
Browse files Browse the repository at this point in the history
Insert `_id_key` into CloudCannon array structures,
so that structures are matched against the `_bookshop_name` field
instead of a deep object comparison.
This makes the front matter across a website more resilient
if component schemas change.
  • Loading branch information
bglw committed Oct 6, 2021
1 parent 01ba099 commit e9a1650
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def self.add_structure(hash, component)
array_structures = component.delete("structures")
array_structures.each do |key|
hash[key] ||= {}
hash[key]["id_key"] = "_bookshop_name"
hash[key]["values"] ||= []
hash[key]["values"].push(component)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module CloudCannonJekyllBookshop
output_data = JSON.parse TestHelpers.read_output_file("_cloudcannon/info.json")

info_diff = Hashdiff.diff(output_data.dig("_array_structures", "item_array_structure"), {
"id_key" => "_bookshop_name",
"values" => [
{
"value" => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const addComponentTo = (obj, component) => {
const {structures, ...fields} = component;
structures?.forEach(structure => {
obj[structure] = obj[structure] || {};
obj[structure]["id_key"] = "_bookshop_name"
obj[structure]["values"] = obj[structure]["values"] || [];
obj[structure]["values"].push(fields);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Feature: Eleventy Bookshop CloudCannon Integration
And stdout should not be empty
And site/_site/_cloudcannon/info.json should leniently contain each row:
| text |
| "id_key" : "_bookshop_name" |
| "value" : { "_bookshop_name" : "card" , "card_text" : null, "color" : "Blue" } |
| "label" : "Card" |
| "_select_data" : { "colors" : [ "Red" , "Blue" ] } |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Feature: Jekyll Bookshop CloudCannon Integration
Then stderr should be empty
And site/_site/_cloudcannon/info.json should leniently contain each row:
| text |
| "id_key" : "_bookshop_name" |
| "value" : { "_bookshop_name" : "card" , "card_text" : null, "color" : "Blue" } |
| "label" : "Card" |
| "_select_data" : { "colors" : [ "Red" , "Blue" ] } |
Expand Down

0 comments on commit e9a1650

Please sign in to comment.