logo

Grimgrains

Unnamed repository; edit this file 'description' to name the repository.
commit: 818c03c70b0ed0542957cc97cd0b61fb570b9265
parent 93423d06f2ee74d7328ff4edf6e887fec40aea17
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date:   Wed, 19 Jun 2019 06:03:01 +0900

Added 404 page.

Diffstat:

Mindex.html6+++---
Mriven.html7++++---
Dscripts/database/Whyisamassivecleavermoreeffectiveatchoppingvegetab13-------------
Rscripts/database/ingredients.js -> scripts/database/ingredients.ndtl0
Rscripts/database/pages.js -> scripts/database/pages.ndtl0
Rscripts/database/recipes.js -> scripts/database/recipes.ndtl0
Mscripts/templates/search.js49+++++++++++++++++++++++++++++++++++++++++++++----
7 files changed, 52 insertions(+), 23 deletions(-)

diff --git a/index.html b/index.html @@ -31,9 +31,9 @@ <script src="scripts/nodes/dom.js"></script> <script src="scripts/nodes/document.js"></script> - <script src="scripts/database/ingredients.js"></script> - <script src="scripts/database/recipes.js"></script> - <script src="scripts/database/pages.js"></script> + <script src="scripts/database/ingredients.ndtl"></script> + <script src="scripts/database/recipes.ndtl"></script> + <script src="scripts/database/pages.ndtl"></script> <script src="scripts/templates/recipe.js"></script> <script src="scripts/templates/ingredient.js"></script> diff --git a/riven.html b/riven.html @@ -15,9 +15,10 @@ <script src="scripts/nodes/dom.js"></script> <script src="scripts/nodes/document.js"></script> - <script src="scripts/database/ingredients.js"></script> - <script src="scripts/database/recipes.js"></script> - <script src="scripts/database/pages.js"></script> + <script src="scripts/database/ingredients.ndtl"></script> + <script src="scripts/database/recipes.ndtl"></script> + <script src="scripts/database/pages.ndtl"></script> + <script src="scripts/templates/home.js"></script> <script src="scripts/templates/search.js"></script> diff --git a/scripts/database/Whyisamassivecleavermoreeffectiveatchoppingvegetab b/scripts/database/Whyisamassivecleavermoreeffectiveatchoppingvegetab @@ -1,12 +0,0 @@ - - -Cleaver - -The cleaver, or the chinese chef's knife, is a less brutish version of the meat cleaver. This tool has a wide variety of purposes, with it, you can dice, slice and julienne vegetables. After the item has been cut into bits, you can use the wide blade to scoop everything up. There is no real need for other knives in your artillery. - -When selecting your cleaver, aim for a harder grade of steel – somewhere between 57-58 on the {{Rockwell Hardness Scale|https://en.wikipedia.org/wiki/Rockwell_scale}}. A good steel produces a finer edge, and holds its sharpness. The angle of the blade is also important, 22 degrees is most common. - -The handle of the cleaver should not be too thick or too small, the size has to allow the hand to wrap around it and to just touch the other side of your thumb. Traditionally, Chinese cleavers are made of carbon steel, but because these are prone to rust stainless steel is preferred (a mixture of carbon and SS is also good). - -http://piqueyeater.com/eats/foodtips-knives-qualities-good-knife/ -From the Earth: Chinese Vegetarian Cooking, Eileen Yin-Fei Lo, Macmillan USA, 1995- \ No newline at end of file diff --git a/scripts/database/ingredients.js b/scripts/database/ingredients.ndtl diff --git a/scripts/database/pages.js b/scripts/database/pages.ndtl diff --git a/scripts/database/recipes.js b/scripts/database/recipes.ndtl diff --git a/scripts/templates/search.js b/scripts/templates/search.js @@ -3,18 +3,59 @@ function SearchTemplate (id, rect) { this.glyph = NODE_GLYPHS.render - // Create the recipe body + // Create the search body this.answer = function (q) { var html = '' return { - core: { - content: 'sup', - related: 'hello' + title: `GrimGrains — Search`, + view: { + header: { + search: 'search' + }, + core: { + content: make_content(q), + related: '' + } } } + } + + function make_content (q) { + var html = '' + + const index = Object.keys(q.tables.ingredients).concat(Object.keys(q.tables.recipes)) + const similar = findSimilar(q.name.toUpperCase(), index) + + html += ` + <h1 class='name'>Could not find "${q.name}"</h1> + <h2 class='serving'>404</h2> + <hr /> + <p>Did you mean <a onclick="Ø('query').bang('${similar[0].word.toLowerCase()}')" href='#${similar[0].word.toLowerCase().to_url()}'>${similar[0].word.toLowerCase()}</a>, <a onclick="Ø('query').bang('${similar[1].word.toLowerCase()}')" href='#${similar[1].word.toLowerCase().to_url()}'>${similar[1].word.toLowerCase()}</a> or <a onclick="Ø('query').bang('${similar[2].word.toLowerCase()}')" href='#${similar[2].word.toLowerCase().to_url()}'>${similar[2].word.toLowerCase()}</a>.</p>` return html } + + function findSimilar (target, list) { + const similar = [] + for (const key in list) { + const word = list[key] + similar.push({ word: word, value: similarity(target, word) }) + } + return similar.sort(function (a, b) { + return a.value - b.value + }).reverse() + } + + function similarity (a, b) { + let val = 0 + for (let i = 0; i < a.length; ++i) { val += b.indexOf(a.substr(i)) > -1 ? 1 : 0 } + for (let i = 0; i < b.length; ++i) { val += a.indexOf(b.substr(i)) > -1 ? 1 : 0 } + a = a.split('').sort().join('') + b = b.split('').sort().join('') + for (let i = 0; i < a.length; ++i) { val += b.indexOf(a.substr(i)) > -1 ? 1 : 0 } + for (let i = 0; i < b.length; ++i) { val += a.indexOf(b.substr(i)) > -1 ? 1 : 0 } + return val + } }