Skip to content

Commit

Permalink
fix: quote some strings in knowledge panel JSON output (#6076)
Browse files Browse the repository at this point in the history
* fix: quote some strings in knowledge panel JSON output

* fix: quote some strings in knowledge panel JSON output
  • Loading branch information
stephanegigandet authored Nov 16, 2021
1 parent c9036ec commit d9ebe60
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
19 changes: 10 additions & 9 deletions lib/ProductOpener/KnowledgePanels.pm
Original file line number Diff line number Diff line change
Expand Up @@ -300,21 +300,22 @@ sub create_panel_from_json_template ($$$$$$) {
or do {
# The JSON generated by the template is invalid
my $json_decode_error = $@;
$product_ref->{"knowledge_panels_" . $target_lc}{$panel_id} = {
"template" => $panel_template,
"json_error" => $json_decode_error,
"json" => $panel_json,
"json_debug_url" => "$static_subdomain/files/debug/knowledge_panels/$panel_id.json"
};

# Save the JSON file so that it can be more easily debugged
# Save the JSON file so that it can be more easily debugged, and that we can monitor issues
my $target_file = "/files/debug/knowledge_panels/$panel_id." . $product_ref->{code} . ".json";
(-e "$www_root/files") or mkdir("$www_root/files", 0755);
(-e "$www_root/files/debug") or mkdir("$www_root/files/debug", 0755);
(-e "$www_root/files/debug/knowledge_panels") or mkdir("$www_root/files/debug/knowledge_panels", 0755);
my $target_file = "$www_root/files/debug/knowledge_panels/$panel_id.json";
open(my $out, ">:encoding(UTF-8)", $target_file) or die "cannot open $target_file";
open(my $out, ">:encoding(UTF-8)", $www_root . $target_file) or die "cannot open $www_root/$target_file";
print $out $panel_json;
close($out);

$product_ref->{"knowledge_panels_" . $target_lc}{$panel_id} = {
"template" => $panel_template,
"json_error" => $json_decode_error,
"json" => $panel_json,
"json_debug_url" => $static_subdomain . $target_file
};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"text_type": "summary",
"html": `
<p>The carbon emission figure comes from ADEME's Agribalyse database, for the category:
<a href=\"https://agribalyse.ademe.fr/app/aliments/[% product.ecoscore_data.agribalyse.code %]\">[% panel.agribalyse_category_name %]</a>
<a href=\"https://agribalyse.ademe.fr/app/aliments/[% product.ecoscore_data.agribalyse.code %]\">[% panel.agribalyse_category_name.dquote %]</a>
([% lang('source_ademe_agribalyse') %]
</p>
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
],
"title_element": {
"title": "[% lang('average_impact_of_the_category') %][% sep %]: [% panel.agribalyse_grade FILTER upper %] (Score: [% panel.agribalyse_score %]/100)",
"subtitle": "[% lang('categories_s') FILTER ucfirst %][% sep %]: [% panel.agribalyse_category_name %]",
"subtitle": "[% lang('categories_s') FILTER ucfirst %][% sep %]: [% panel.agribalyse_category_name.dquote %]",
"type": "grade",
"grade": "[% panel.agribalyse_grade %]",
},
Expand Down

0 comments on commit d9ebe60

Please sign in to comment.