commit: c38aa507997b630ae5c4a35852ddf1493c274f27
parent 578ec2d981acf92313bb275d9af2575abdf29068
Author: neauoire <aliceffekt@gmail.com>
Date: Thu, 28 Nov 2019 09:55:03 -0500
*
Diffstat:
2 files changed, 15 insertions(+), 67 deletions(-)
diff --git a/scripts/database/ingredients.ndtl b/scripts/database/ingredients.ndtl
@@ -231,6 +231,7 @@ Black sesame seeds
LONG
& Sesame seeds are added to breads, or over the top of baked goods, they are also baked into {{crackers|crackers}} or sprinkled onto a variety of foods. Popular uses of black sesame seeds also include {*gomashio*} (Japanese sesame salt) and {*chikki*} (Indian sweet brittle). The seeds need stored at 6% moisture or less. If the seed is too moist, it can quickly heat up and become rancid.
Tahini
+ PARENT : Sesame seeds
BREF : Tahini is a condiment made from toasted and ground hulled white sesame seeds. It is a rich source of {*protein*} and {*calcium*}.
LONG
& It is used in {*baba ghanoush*} (roasted eggplant dip), {*pekmez*} (sweet turkish dip), {{hummus|uzumaki hummus bites}} and in many other recipes. Because of its high oil content, it needs to be refrigerated to prevent spoilage. Tahini has high levels of calcium and protein, making it a must ingredient in any plantbased pantry.
diff --git a/scripts/templates/ingredient.js b/scripts/templates/ingredient.js
@@ -28,76 +28,15 @@ function IngredientTemplate (id, rect) {
html += ingredient.BREF ? `<p class='bref'>${ingredient.BREF.to_markup()}</p>` : ''
html += ingredient.LONG ? `${new Runic(ingredient.LONG)}` : ''
html += ingredient.WARN ? `<section id='warn'>${new Runic(ingredient.WARN)}</section>` : ''
- 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'>"
- const parents = ingredient.PARENT.split(',')
-
- for (id in parents) {
- const 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'/>
- <span class='name'>${name.capitalize()}</span>
- </a>
- </li>`
- }
-
- html += '</ul>'
- return html
- }
-
- function make_children (ingredient, all_ingredients) {
- let html = ''
- const 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) {
- const 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'/>
- <span class='name'>${name.capitalize()}</span>
- </a>
- </li>`
- }
+ const parents = ingredient && ingredient.PARENT ? ingredient.PARENT.split(',') : []
+ const children = find_child_ingredients(name, all_ingredients)
+ const related = parents.concat(children)
+ html += related.length > 0 ? `<h2>Related Ingredients</h2><ul class='ingredients'>${related.reduce((acc,ingr) => { return acc+print_ingredient(ingr) },'')}</ul>` : ''
- html += '</ul>'
return html
}
- function make_similar (search_name, recipes, all_ingredients) {
- let html = ''
- const ingredients = find_ingredients(recipes)
- const similar_ingredients = find_similar_ingredients(search_name, ingredients, all_ingredients)
-
- for (id in similar_ingredients) {
- if (similar_ingredients[id][1] < 1) { break }
- const name = similar_ingredients[id][0]
- if (name.toLowerCase() == search_name.toLowerCase()) { continue }
- html += `
- <li class='ingredient'>
- <a onclick="Ø('query').bang('${name}')" href='#${name.to_url()}'>
- <img src='media/ingredients/${name.to_path()}.png'/>
- <span class='name'>${name.capitalize()}</span>
- </a>
- </li>`
- }
- return similar_ingredients.length >= 1 ? `<h2>Related Ingredients</h2><ul class='ingredients'>${html}<hr /></ul>` : ''
- }
-
function find_ingredients (recipes) {
const h = {}
for (id in recipes) {
@@ -135,7 +74,6 @@ function IngredientTemplate (id, rect) {
function find_child_ingredients (search_name, all_ingredients) {
const a = []
-
for (name in all_ingredients) {
const ingr = all_ingredients[name]
if (!ingr.PARENT) { continue }
@@ -144,7 +82,6 @@ function IngredientTemplate (id, rect) {
a.push(name.toLowerCase())
}
}
-
return a
}
@@ -217,4 +154,14 @@ function IngredientTemplate (id, rect) {
}
return Object.keys(ingredients).length
}
+
+ function print_ingredient(name){
+ return `
+ <li class='ingredient'>
+ <a onclick="Ø('query').bang('${name}')" href='#${name.to_url()}'>
+ <img src='media/ingredients/${name.to_path()}.png'/>
+ <span class='name'>${name.capitalize()}</span>
+ </a>
+ </li>`
+ }
}