logo

Grimgrains

[mirror] Plant-based cooking website <https://grimgrains.com/>
commit: 30a0694d8a73a786634fa67deb63690cb8939bfd
parent d3ff738eb4a6d65735040e29fd2a1cdf2d11bcf9
Author: microlith57 <microlith57@gmail.com>
Date:   Sun, 23 Jun 2019 20:48:59 +1200

Add parent and child lists for ingredients

Signed-off-by: microlith57 <microlith57@gmail.com>

Diffstat:

Mscripts/database/ingredients.ndtl10++++++++++
Mscripts/templates/ingredient.js80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
2 files changed, 82 insertions(+), 8 deletions(-)

diff --git a/scripts/database/ingredients.ndtl b/scripts/database/ingredients.ndtl @@ -25,8 +25,10 @@ Lentils BREF : Lentils are considered to be one of the best foods because their chemical structures are not altered by cooking. Lens is the latin name for lentil. Beluga Lentils + Parent : lentils Color : #000000 Brown Lentils + Parent : lentils BREF : The most common variety of lentils, found in most grocery stores. They have a mild, earthy-flavor. Tempeh Color : #875A2C @@ -43,6 +45,7 @@ Edamame Chickpeas Chickpea Chickpea Flour + Parent : chickpea, flour Peas Green Peas Mungbeans @@ -317,16 +320,20 @@ Fenugreek ~ WHOLEGRAINS Whole wheat flour + Parent : flour Buckwheat Buckwheat noodles Buckwheat flour + Parent : flour Quinoa BREF : No description. Whole wheat Einkorn Einkorn Flour + Parent : flour Spelt Spelt Flour + Parent : flour Corn Cornmeal Corn Semolina @@ -346,11 +353,14 @@ Black Glutinous Rice Wholegrain Brown Rice Rice Noodles Rice Flour + Parent : rice, flour Flour BREF : [all_purpose#EFEFEF rice] Plain flour has an average protein content, making it versatile to use in almost any recipe that requires flour. Spelt flour was a staple food during the Bronze age all the way up to medieval times. Brown rice flour is sometimes used as a base to grow mushrooms. Einkorn wheat was one of the first plants to be domesticated and cultivated. It has a high percentage of protein, more than regular wheat. It also has high levels of fat, phosphorus, potassium, pyridoxine (a form of vitamin b6) and beta-carotene, making it more nutritious than other kinds of grains. Another great thing about einkorn is that it isn't as toxic to people on gluten-free diets, it as yet to be proven but it should definitely be looked into! All Purpose Flour + Parent : flour Breadfruit Flour + Parent : flour BREF : The product of dried and ground breadfruit. Can be used to make cakes, pasta and a number of other meals. Wheat Semolina Oatmeal diff --git a/scripts/templates/ingredient.js b/scripts/templates/ingredient.js @@ -12,27 +12,73 @@ function IngredientTemplate (id, rect) { title: `GrimGrains — ${t.name.capitalize()}`, view: { core: { - content: make_ingredient(t.name, ingredient, t.tables.recipes), + content: make_ingredient(t.name, ingredient, t.tables.recipes, t.tables.ingredients), related: make_related(related_recipes(t.name, t.tables.recipes)) } } } } - function make_ingredient (name, ingredient, recipes) { + function make_ingredient (name, ingredient, recipes, all_ingredients) { let html = '' - html += `<h1>${ingredient.TYPE ? ingredient.TYPE.capitalize() + '/' : ''}${name.capitalize()}</h1>` + html += `<h1>${name.capitalize()}</h1>` html += ingredient.BREF ? `<p class='bref'>${ingredient.BREF.to_markup()}</p>` : '' html += ingredient.LONG ? `${new Runic(ingredient.LONG)}` : '' - html += `${make_similar(name, recipes)}` + html += `${make_parents(ingredient)}` + html += `${make_children(name, all_ingredients)}` + html += `${make_similar(name, recipes, all_ingredients)}` + return html + } + + function make_parents (ingredient) { + let html = '' + if (!ingredient.PARENT) {return html} + + html += "<h2>Parent Ingredients</h2><ul class='ingredients'>" + let parents = ingredient.PARENT.split(",") + + for (id in parents) { + let name = parents[id].trim() + html += ` + <li class='ingredient'> + <a onclick="Ø('query').bang('${name}')" href='#${name.to_url()}'> + <img src='media/ingredients/${name.to_path()}.png'/> + </a> + <t class='name'>${name.capitalize()}</t> + </li>` + } + + html += "</ul>" + return html + } + + function make_children (ingredient, all_ingredients) { + let html = '' + let child_ingredients = find_child_ingredients(ingredient, all_ingredients) + if (child_ingredients.length == 0) {return html} + + html += "<h2>Child Ingredients</h2><ul class='ingredients'>" + + for (id in child_ingredients) { + let name = child_ingredients[id] + html += ` + <li class='ingredient'> + <a onclick="Ø('query').bang('${name}')" href='#${name.to_url()}'> + <img src='media/ingredients/${name.to_path()}.png'/> + </a> + <t class='name'>${name.capitalize()}</t> + </li>` + } + + html += "</ul>" return html } - function make_similar (search_name, recipes) { + function make_similar (search_name, recipes, all_ingredients) { let html = '' let ingredients = find_ingredients(recipes) - let similar_ingredients = find_similar_ingredients(search_name, ingredients) + let similar_ingredients = find_similar_ingredients(search_name, ingredients, all_ingredients) for (id in similar_ingredients) { if (similar_ingredients[id][1] < 1) { break } @@ -46,7 +92,7 @@ function IngredientTemplate (id, rect) { <t class='name'>${name.capitalize()}</t> </li>` } - return similar_ingredients.length > 1 ? `<h2>Related Ingredients</h2><ul class='ingredients'>${html}<hr /></ul>` : '' + return similar_ingredients.length >= 1 ? `<h2>Related Ingredients</h2><ul class='ingredients'>${html}<hr /></ul>` : '' } function find_ingredients (recipes) { @@ -63,10 +109,13 @@ function IngredientTemplate (id, rect) { return h } - function find_similar_ingredients (name, ingredients) { + function find_similar_ingredients (name, ingredients, all_ingredients) { let a = [] + + let children = find_child_ingredients(name, all_ingredients) for (id in ingredients) { + if (children.includes(id.toLowerCase())) {continue} let words = id.toLowerCase().split(' ') let index = similarity(name.toLowerCase().split(' '), words) if (index > 0) { @@ -80,6 +129,21 @@ function IngredientTemplate (id, rect) { return a.reverse() } + + function find_child_ingredients (search_name, all_ingredients) { + let a = [] + + for (name in all_ingredients) { + let ingr = all_ingredients[name] + if (!ingr.PARENT) { continue } + let parents = ingr.PARENT.split(",").map(function (name) {return name.trim().toLowerCase()}) + if (parents.includes(search_name.toLowerCase())) { + a.push(name.toLowerCase()) + } + } + + return a + } function similarity (a, b) { let score = 0