diff --git a/_layouts/recipe.html b/_layouts/recipe.html index 0ed0958d5..d08565d00 100644 --- a/_layouts/recipe.html +++ b/_layouts/recipe.html @@ -50,15 +50,23 @@

Components

{% endif %} {% if page.ingredients %} -

Ingredients

+ {% assign servings = page.servings | default: 1 %} +

Ingredients for servings

{% endif %} -
@@ -103,7 +111,15 @@

{{recipe.title}}

Ingredients

@@ -154,6 +170,88 @@

Steps

$('html, body').animate({scrollTop: y-height-16}, 200); }); + function numberToPretty(inNum) { + let wholeNumber = Math.trunc(inNum); + if (wholeNumber == 0) { + wholeNumber = ""; + } + + let fraction = inNum % 1; + + let fracRep; + if (Math.abs(fraction) < 0.0001) { + fracRep = '' + } else if (Math.abs(fraction - 1 / 2) < 0.0001) { + fracRep = " ½"; + } else if (Math.abs(fraction - 1 / 4) < 0.0001) { + fracRep = " ¼"; + } else if (Math.abs(fraction - 3 / 4) < 0.0001) { + fracRep = " ¾"; + } else if (Math.abs(fraction - 1 / 3) < 0.0001) { + fracRep = " ⅓"; + } else if (Math.abs(fraction - 2 / 3) < 0.0001) { + fracRep = " ⅔"; + } else if (Math.abs(fraction - 1 / 8) < 0.0001) { + fracRep = " ⅛"; + } else if (Math.abs(fraction - 3 / 8) < 0.0001) { + fracRep = " ⅜"; + } else if (Math.abs(fraction - 5 / 8) < 0.0001) { + fracRep = " ⅝"; + } else if (Math.abs(fraction - 7 / 8) < 0.0001) { + fracRep = " ⅞"; + } else if (Math.abs(fraction - 1 / 6) < 0.0001) { + fracRep = " ⅙"; + } else if (Math.abs(fraction - 5 / 6) < 0.0001) { + fracRep = " ⅚"; + } else if (Math.abs(fraction - 1 / 9) < 0.0001) { + fracRep = " 19"; + } else if (Math.abs(fraction - 2 / 9) < 0.0001) { + fracRep = " 29"; + } else if (Math.abs(fraction - 4 / 9) < 0.0001) { + fracRep = " 49"; + } else if (Math.abs(fraction - 5 / 9) < 0.0001) { + fracRep = " 59"; + } else if (Math.abs(fraction - 7 / 9) < 0.0001) { + fracRep = " 79"; + } else if (Math.abs(fraction - 8 / 9) < 0.0001) { + fracRep = " 89"; + } else { + fracRep = '' + fraction.toFixed(3); + } + + return wholeNumber + fracRep; + } + + function calculateIngredients(scale) { + $('li[itemprop=recipeIngredient]').each(function(index, elem) { + let quantity = $(elem).data('quantity'); + if (quantity == '') { + return; + } + + let unit = $(elem).data('unit'); + let text = $(elem).data('text'); + + let info = '' + numberToPretty(scale * quantity) + ' '; + if (unit != '') { + info += unit + ' '; + } + info += text; + + $(elem).children('p').html(info); + }); + } + + $('#servings-count').change(function() { + let servings = $(this).val(); + let baseServings = $(this).data('base-servings'); + let scale = servings / baseServings; + + calculateIngredients(scale); }); + calculateIngredients(1); + + }); + diff --git a/_recipes/banana-bread.md b/_recipes/banana-bread.md index f942d9deb..f3055c668 100644 --- a/_recipes/banana-bread.md +++ b/_recipes/banana-bread.md @@ -1,21 +1,22 @@ --- layout: recipe -title: "Banana Bread" +title: "Banana Bread" image: banana-bread.jpg imagecredit: https://flic.kr/p/7HZmzn tags: breakfast, baking +servings: 1 ingredients: -- 4 bananas -- 1/2 cup butter -- 1/2 cup sugar -- 2 eggs -- 2 cups flour -- 1/2 tsp baking soda -- 1 tsp baking powder +- 4|banana(s) +- 0.5|cup(s)|butter +- 0.5|cup(s)|sugar +- 2|egg(s) +- 2|cup(s)|flour +- 0.5|tsp|baking soda +- 1|tsp|baking powder - pinch salt -- 1/4 cup nuts (we like pecans) +- 0.25|cup(s)|nuts (we like pecans) directions: - Beat the eggs, then cream with the butter and sugar @@ -25,4 +26,4 @@ directions: --- -From Angie's mom \ No newline at end of file +From Angie's mom diff --git a/css/main.scss b/css/main.scss index f22d26ed4..b852ea730 100755 --- a/css/main.scss +++ b/css/main.scss @@ -21,6 +21,9 @@ ul li input{position: absolute; top:5px; left:0; opacity:0.5;} .search input:focus{outline:none; border:2px solid #007FFF;} .search{transition:.3s ease height; height:90vh; display:flex; flex-direction: column; justify-content:center;} +.servings-input{border-radius:5px; border:2px solid #eee; box-shadow:0 0 14px rgba(#007FFF,0.1); width:20%} +.servings-input:focus{outline:none; border:2px solid #007FFF;} + .hero{height:150px;} .post h1{margin-top:6rem} .post ol, .post ul{}