Encode ingredients to handle special characters

This commit is contained in:
maeligg 2023-01-04 18:11:54 +01:00
parent f58a99b04b
commit 20dac4790c
3 changed files with 5392 additions and 14 deletions

View file

@ -63,7 +63,7 @@ module.exports = config => {
// This workaround is needed so we can transform it back into an array with Alpine (we can't split on "," as it can be included within the items) // This workaround is needed so we can transform it back into an array with Alpine (we can't split on "," as it can be included within the items)
config.addFilter('arrayToString', function(value) { config.addFilter('arrayToString', function(value) {
return value.join('£'); return encodeURI(value.join('£'));
}); });
/* Shortcodes */ /* Shortcodes */

5400
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -11,7 +11,7 @@
<a class="c-tags__tag" href="/tags/{{ tag | noEmoji | slug }}">{{ tag }}</a> <a class="c-tags__tag" href="/tags/{{ tag | noEmoji | slug }}">{{ tag }}</a>
{% endfor %} {% endfor %}
</div> </div>
<div class="c-recipe__ingredients-wrapper" x-data='{currentServings: {{ servings if not servings == "" else false }}, ingredients: "{{ ingredients | arrayToString }}".split("£") }'> <div class="c-recipe__ingredients-wrapper" x-data='{currentServings: {{ servings if not servings == "" else false }}, ingredients: decodeURI("{{ ingredients | arrayToString }}").split("£") }'>
{% if time or not servings == "" %} {% if time or not servings == "" %}
<div class="c-recipe__additional-info"> <div class="c-recipe__additional-info">
{% if time %} {% if time %}
@ -66,7 +66,7 @@
<script> <script>
function adaptQuantity (ingredient, originalServings, currentServings) { function adaptQuantity (ingredient, originalServings, currentServings) {
return ingredient.replace(/(\d|\.|,)+/, match => Number(Math.round(parseFloat(match) * currentServings / originalServings + 'e' + 2) + 'e-' + 2)); return ingredient.replace(/(\d|\.|,)+/, match => Number(Math.round(parseFloat(match.replace(',', '.')) * currentServings / originalServings + 'e' + 2) + 'e-' + 2));
} }
</script> </script>
{% endblock %} {% endblock %}