logo

Grimgrains

[mirror] Plant-based cooking website <https://grimgrains.com/>
commit: d3ff738eb4a6d65735040e29fd2a1cdf2d11bcf9
parent 5ecfecb8c445b3ffe8b2168e9a35dff1a638cae3
Author: microlith57 <microlith57@gmail.com>
Date:   Sun, 23 Jun 2019 12:16:44 +1200

Merge remote-tracking branch 'hundredrabbits/master'


Diffstat:

M404.html2+-
Mindex.html2+-
Mriven.html2+-
Mscripts/lib/riven.graph.js82++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mscripts/lib/riven.js36++++++++++++++++++------------------
Mscripts/lib/runic.js41++++++++++++++++++++---------------------
Mscripts/nodes/indental.js20++++++++++----------
Mscripts/nodes/query.js6+++---
Mscripts/nodes/router.js10+++++-----
Mscripts/nodes/template.js4++--
Mscripts/templates/home.js32++++++++++++++++----------------
Mscripts/templates/ingredient.js50+++++++++++++++++++++++++-------------------------
Mscripts/templates/page.js4++--
Mscripts/templates/recipe.js42+++++++++++++++++++++---------------------
Mscripts/templates/search.js4++--
15 files changed, 168 insertions(+), 169 deletions(-)

diff --git a/404.html b/404.html @@ -31,7 +31,7 @@ permalink: /404.html <body style='background:black; color:white'> <script> // Find current path (relative to grimgrains.com) - var target = decodeURI(window.location.pathname); + let target = decodeURI(window.location.pathname); // Fancy slugify regex bit target = target.toLowerCase(); diff --git a/index.html b/index.html @@ -48,7 +48,7 @@ </head> <body> <script> - var RIVEN = new Riven(); + let RIVEN = new Riven(); graph() </script> diff --git a/riven.html b/riven.html @@ -33,7 +33,7 @@ </head> <body> <script> - var RIVEN = new Riven_Graph(); + let RIVEN = new Riven_Graph(); graph() RIVEN.graph(); </script> diff --git a/scripts/lib/riven.graph.js b/scripts/lib/riven.graph.js @@ -1,31 +1,31 @@ function Riven_Graph () { Riven.call(this) - var GRID_SIZE = 20 + let GRID_SIZE = 20 this.el = document.createElementNS('http://www.w3.org/2000/svg', 'svg') document.body.appendChild(this.el) this.graph = function () { - var html = '' + let html = '' for (id in this.network) { - var node = this.network[id] + let node = this.network[id] html += draw_routes(node) } for (id in this.network) { - var node = this.network[id] + let node = this.network[id] html += draw_node(node) } this.el.innerHTML = html } function draw_routes (node) { - var html = '' + let html = '' for (id in node.ports) { - var port = node.ports[id] - var pos = port ? get_port_position(port) : { x: 0, y: 0 } + let port = node.ports[id] + let pos = port ? get_port_position(port) : { x: 0, y: 0 } for (route_id in port.routes) { - var route = port.routes[route_id] + let route = port.routes[route_id] if (!route) { continue } html += route ? draw_connection(port, route) : '' } @@ -34,7 +34,7 @@ function Riven_Graph () { } function draw_node (node) { - var rect = get_rect(node) + let rect = get_rect(node) return ` <g class='node ${node.is_mesh ? 'mesh' : ''}' id='node_${node.id}'> @@ -46,7 +46,7 @@ function Riven_Graph () { } function draw_ports (node) { - var html = '' + let html = '' for (id in node.ports) { html += draw_port(node.ports[id]) } @@ -54,12 +54,12 @@ function Riven_Graph () { } function draw_glyph (node) { - var rect = get_rect(node) + let rect = get_rect(node) return !node.is_mesh && node.glyph ? `<path class='glyph' transform="translate(${rect.x + (GRID_SIZE / 4)},${rect.y - (GRID_SIZE / 4)}) scale(0.1)" d='${node.glyph}'/>` : '' } function draw_port (port) { - var pos = port ? get_port_position(port) : { x: 0, y: 0 } + let pos = port ? get_port_position(port) : { x: 0, y: 0 } return `<g id='${port.host.id}_port_${port.id}'>${(port.type == PORT_TYPES.request || port.type == PORT_TYPES.answer) ? `<path d='${draw_diamond(pos)}' class='port ${port.type} ${port.host.ports[id] && port.host.ports[id].route ? 'route' : ''}' />` : `<circle cx='${pos.x}' cy="${pos.y}" r="${parseInt(GRID_SIZE / 6)}" class='port ${port.type} ${port.host.ports[id] && port.host.ports[id].route ? 'route' : ''}'/>`}</g>` } @@ -73,9 +73,9 @@ function Riven_Graph () { function is_bidirectional (a, b) { for (id in a.ports.output.routes) { - var route_a = a.ports.output.routes[id] + let route_a = a.ports.output.routes[id] for (id in a.ports.request.routes) { - var route_b = a.ports.request.routes[id] + let route_b = a.ports.request.routes[id] if (route_a.host.id == route_b.host.id) { return true } @@ -85,13 +85,13 @@ function Riven_Graph () { } function draw_connection_output (a, b) { - var pos_a = get_port_position(a) - var pos_b = get_port_position(b) - var pos_m = middle(pos_a, pos_b) - var pos_c1 = { x: (pos_m.x + (pos_a.x + GRID_SIZE)) / 2, y: pos_a.y } - var pos_c2 = { x: (pos_m.x + (pos_b.x - GRID_SIZE)) / 2, y: pos_b.y } + let pos_a = get_port_position(a) + let pos_b = get_port_position(b) + let pos_m = middle(pos_a, pos_b) + let pos_c1 = { x: (pos_m.x + (pos_a.x + GRID_SIZE)) / 2, y: pos_a.y } + let pos_c2 = { x: (pos_m.x + (pos_b.x - GRID_SIZE)) / 2, y: pos_b.y } - var path = '' + let path = '' path += `M${pos_a.x},${pos_a.y} L${pos_a.x + GRID_SIZE},${pos_a.y} ` path += `Q${pos_c1.x},${pos_c1.y} ${pos_m.x},${pos_m.y} ` @@ -103,13 +103,13 @@ function Riven_Graph () { } function draw_connection_request (a, b) { - var pos_a = get_port_position(a) - var pos_b = get_port_position(b) - var pos_m = middle(pos_a, pos_b) - var pos_c1 = { x: pos_a.x, y: (pos_m.y + (pos_a.y + GRID_SIZE)) / 2 } - var pos_c2 = { x: pos_b.x, y: (pos_m.y + (pos_b.y - GRID_SIZE)) / 2 } + let pos_a = get_port_position(a) + let pos_b = get_port_position(b) + let pos_m = middle(pos_a, pos_b) + let pos_c1 = { x: pos_a.x, y: (pos_m.y + (pos_a.y + GRID_SIZE)) / 2 } + let pos_c2 = { x: pos_b.x, y: (pos_m.y + (pos_b.y - GRID_SIZE)) / 2 } - var path = '' + let path = '' path += `M${pos_a.x},${pos_a.y} L${pos_a.x},${pos_a.y + GRID_SIZE} ` path += `Q${pos_c1.x},${pos_c1.y} ${pos_m.x},${pos_m.y} ` @@ -121,13 +121,13 @@ function Riven_Graph () { } function draw_connection_bidirectional (a, b) { - var pos_a = get_port_position(a) - var pos_b = get_port_position(b) - var pos_m = middle(pos_a, pos_b) - var pos_c1 = { x: pos_a.x, y: (pos_m.y + (pos_a.y + GRID_SIZE)) / 2 } - var pos_c2 = { x: pos_b.x, y: (pos_m.y + (pos_b.y - GRID_SIZE)) / 2 } + let pos_a = get_port_position(a) + let pos_b = get_port_position(b) + let pos_m = middle(pos_a, pos_b) + let pos_c1 = { x: pos_a.x, y: (pos_m.y + (pos_a.y + GRID_SIZE)) / 2 } + let pos_c2 = { x: pos_b.x, y: (pos_m.y + (pos_b.y - GRID_SIZE)) / 2 } - var path = '' + let path = '' path += `M${pos_a.x},${pos_a.y} L${pos_a.x},${pos_a.y + GRID_SIZE} ` path += `L${pos_a.x},${pos_m.y} L${pos_b.x},${pos_m.y}` @@ -137,13 +137,13 @@ function Riven_Graph () { } function draw_diamond (pos) { - var r = GRID_SIZE / 6 + let r = GRID_SIZE / 6 return `M${pos.x - (r)},${pos.y} L${pos.x},${pos.y - (r)} L${pos.x + (r)},${pos.y} L${pos.x},${pos.y + (r)} Z` } function get_port_position (port) { - var rect = get_rect(port.host) - var offset = { x: 0, y: 0 } + let rect = get_rect(port.host) + let offset = { x: 0, y: 0 } if (port.type == PORT_TYPES.output) { offset = { x: GRID_SIZE * 2, y: GRID_SIZE / 2 } } else if (port.type == PORT_TYPES.input) { @@ -157,14 +157,14 @@ function Riven_Graph () { } function get_rect (node) { - var rect = node.rect - var x = node.rect.x * GRID_SIZE - var y = node.rect.y * GRID_SIZE - var w = node.rect.w * GRID_SIZE - var h = node.rect.h * GRID_SIZE + let rect = node.rect + let x = node.rect.x * GRID_SIZE + let y = node.rect.y * GRID_SIZE + let w = node.rect.w * GRID_SIZE + let h = node.rect.h * GRID_SIZE if (node.parent) { - var offset = get_rect(node.parent) + let offset = get_rect(node.parent) x += offset.x y += offset.y } diff --git a/scripts/lib/riven.js b/scripts/lib/riven.js @@ -8,10 +8,10 @@ function Riven () { // QUERY function Ø (s, network = RIVEN.network) { - var id = s.toLowerCase() + let id = s.toLowerCase() if (id.indexOf(' ') > -1) { - var node_id = id.split(' ')[0] - var port_id = id.split(' ')[1] + let node_id = id.split(' ')[0] + let port_id = id.split(' ')[1] return network[node_id] && network[node_id].ports[port_id] ? network[node_id].ports[port_id] : null } else if (network[id]) { return network[id] @@ -38,7 +38,7 @@ function Node (id, rect = { x: 0, y: 0, w: 2, h: 2 }) { } this.create = function (pos = { x: 0, y: 0 }, type = Node, ...params) { - var node = new type(this.id, rect, ...params) + let node = new type(this.id, rect, ...params) this.rect.x = pos.x this.rect.y = pos.y node.setup() @@ -47,7 +47,7 @@ function Node (id, rect = { x: 0, y: 0, w: 2, h: 2 }) { } this.mesh = function (pos, n) { - var node = new Mesh(this.id, pos) + let node = new Mesh(this.id, pos) node.rect.x = pos.x node.rect.y = pos.y node.setup() @@ -92,9 +92,9 @@ function Node (id, rect = { x: 0, y: 0, w: 2, h: 2 }) { this.signal = function (target) { for (port_id in this.ports) { - var port = this.ports[port_id] + let port = this.ports[port_id] for (route_id in port.routes) { - var route = port.routes[route_id] + let route = port.routes[route_id] if (!route || !route.host || route.host.id != target.toLowerCase()) { continue } return route.host } @@ -106,16 +106,16 @@ function Node (id, rect = { x: 0, y: 0, w: 2, h: 2 }) { this.send = function (payload) { for (route_id in this.ports.output.routes) { - var route = this.ports.output.routes[route_id] + let route = this.ports.output.routes[route_id] if (!route) { continue } route.host.receive(payload) } } this.receive = function (q) { - var port = this.ports.output + let port = this.ports.output for (route_id in port.routes) { - var route = port.routes[route_id] + let route = port.routes[route_id] if (route) { route.host.receive(q) } @@ -133,11 +133,11 @@ function Node (id, rect = { x: 0, y: 0, w: 2, h: 2 }) { } this.request = function (q) { - var payload = {} + let payload = {} for (route_id in this.ports.request.routes) { - var route = this.ports.request.routes[route_id] + let route = this.ports.request.routes[route_id] if (!route) { continue } - var answer = route.host.answer(q) + let answer = route.host.answer(q) if (!answer) { continue } payload[route.host.id] = answer } @@ -167,9 +167,9 @@ function Node (id, rect = { x: 0, y: 0, w: 2, h: 2 }) { this.setup = function () {} this.update = function () { - var bounds = { x: 0, y: 0 } + let bounds = { x: 0, y: 0 } for (id in this.children) { - var node = this.children[id] + let node = this.children[id] bounds.x = node.rect.x > bounds.x ? node.rect.x : bounds.x bounds.y = node.rect.y > bounds.y ? node.rect.y : bounds.y } @@ -179,9 +179,9 @@ function Node (id, rect = { x: 0, y: 0, w: 2, h: 2 }) { } } -var PORT_TYPES = { default: 'default', input: 'input', output: 'output', request: 'request', answer: 'answer' } -var ROUTE_TYPES = { default: 'default', request: 'request' } -var NODE_GLYPHS = { +let PORT_TYPES = { default: 'default', input: 'input', output: 'output', request: 'request', answer: 'answer' } +let ROUTE_TYPES = { default: 'default', request: 'request' } +let NODE_GLYPHS = { default: 'M150,60 L150,60 L60,150 L150,240 L240,150 Z', router: 'M60,120 L60,120 L150,120 L240,60 M60,150 L60,150 L240,150 M60,180 L60,180 L150,180 L240,240', parser: 'M60,60 L60,60 L240,60 M120,120 A30,30 0 0,1 150,150 M150,150 A30,30 0 0,0 180,180 M180,180 L180,180 L240,180 M120,120 L120,120 L60,120 M60,240 L60,240 L240,240 M240,120 L240,120 L180,120 M60,180 L60,180 L120,180', diff --git a/scripts/lib/runic.js b/scripts/lib/runic.js @@ -27,7 +27,7 @@ function Runic (raw) { this.all.push({ rune: rune, item: item }) }, pop: function () { - var copy = this.copy(this.all) + let copy = this.copy(this.all) this.all = [] return copy }, @@ -43,8 +43,8 @@ function Runic (raw) { } this.media = function (val) { - var service = val.split(' ')[0] - var id = val.split(' ')[1] + let service = val.split(' ')[0] + let id = val.split(' ')[1] if (service == 'itchio') { return `<iframe frameborder="0" src="https://itch.io/embed/${id}?link_color=000000" width="600" height="167"></iframe>` @@ -58,17 +58,16 @@ function Runic (raw) { this.parse = function (raw = this.raw) { if (!raw) { return '' } - var html = '' - var lines = raw - var lines = !Array.isArray(raw) ? raw.split('\n') : raw + let html = '' + let lines = !Array.isArray(raw) ? raw.split('\n') : raw for (id in lines) { - var char = lines[id].substr(0, 1).trim().toString() - var rune = this.runes[char] - var trail = lines[id].substr(1, 1) + let char = lines[id].substr(0, 1).trim().toString() + let rune = this.runes[char] + let trail = lines[id].substr(1, 1) if (char == '$') { html += '<p>' + Ø('operation').request(lines[id].substr(2)).to_markup() + '</p>'; continue } if (char == '%') { html += this.media(lines[id].substr(2)); continue } - var line = lines[id].substr(2).to_markup() + let line = lines[id].substr(2).to_markup() if (!line || line.trim() == '') { continue } if (!rune) { console.log(`Unknown rune:${char} : ${line}`) } if (trail != ' ') { console.warn('Runic', 'Non-rune[' + trail + '] at:' + id + '(' + line + ')'); continue } @@ -82,13 +81,13 @@ function Runic (raw) { } this.render_stash = function () { - var rune = this.stash.rune - var stash = this.stash.pop() + let rune = this.stash.rune + let stash = this.stash.pop() - var html = '' + let html = '' for (id in stash) { - var rune = stash[id].rune - var line = stash[id].item + let rune = stash[id].rune + let line = stash[id].item html += rune.wrap ? `<${rune.sub}><${rune.wrap}>${line.replace(/\|/g, `</${rune.wrap}><${rune.wrap}>`).trim()}</${rune.wrap}></${rune.sub}>` : `<${rune.sub}>${line}</${rune.sub}>` } return `<${rune.tag} class='${rune.class}'>${html}</${rune.tag}>` @@ -128,16 +127,16 @@ String.prototype.to_markup = function () { html = html.replace(/{\*/g, '<b>').replace(/\*}/g, '</b>') html = html.replace(/{\#/g, "<code class='inline'>").replace(/\#}/g, '</code>') - var parts = html.split('{{') + let parts = html.split('{{') for (id in parts) { - var part = parts[id] + let part = parts[id] if (part.indexOf('}}') == -1) { continue } - var content = part.split('}}')[0] + let content = part.split('}}')[0] if (content.substr(0, 1) == '$') { html = html.replace(`{{${content}}}`, Ø('operation').request(content.replace('$', ''))); continue } // if(content.substr(0,1) == "%"){ html = html.replace(`{{${content}}}`, this.media(content)); continue; } - var target = content.indexOf('|') > -1 ? content.split('|')[1] : content - var name = content.indexOf('|') > -1 ? content.split('|')[0] : content - var external = (target.indexOf('https:') > -1 || target.indexOf('http:') > -1 || target.indexOf('dat:') > -1) + let target = content.indexOf('|') > -1 ? content.split('|')[1] : content + let name = content.indexOf('|') > -1 ? content.split('|')[0] : content + let external = (target.indexOf('https:') > -1 || target.indexOf('http:') > -1 || target.indexOf('dat:') > -1) html = html.replace(`{{${content}}}`, external ? `<a href='${target}' class='external' target='_blank'>${name}</a>` : `<a class='local' href="#${target.to_url()}" onclick="Ø('query').bang('${target}')">${name}</a>`) } return html diff --git a/scripts/nodes/indental.js b/scripts/nodes/indental.js @@ -23,10 +23,10 @@ function IndentalNode (id, rect, type) { function build (lines, type) { // Assoc lines - var stack = {} - var target = lines[0] + let stack = {} + let target = lines[0] for (id in lines) { - var line = lines[id] + let line = lines[id] if (line.skip) { continue } target = stack[line.indent - 2] if (target) { target.children.push(line) } @@ -34,21 +34,21 @@ function IndentalNode (id, rect, type) { } // Format - var h = {} + let h = {} for (id in lines) { - var line = lines[id] + let line = lines[id] if (line.skip || line.indent > 0) { continue } - var key = line.content.toUpperCase() + let key = line.content.toUpperCase() h[key] = type ? new type(key, format(line)) : format(line) } return h } function format (line) { - var a = [] - var h = {} + let a = [] + let h = {} for (id in line.children) { - var child = line.children[id] + let child = line.children[id] if (child.key) { h[child.key.toUpperCase()] = child.value } else if (child.children.length == 0 && child.content) { a.push(child.content) } else { h[child.content.toUpperCase()] = format(child) } } return a.length > 0 ? a : h @@ -67,4 +67,4 @@ function IndentalNode (id, rect, type) { } } -var DATABASE = {} +let DATABASE = {} diff --git a/scripts/nodes/query.js b/scripts/nodes/query.js @@ -5,7 +5,7 @@ function QueryNode (id, rect) { this.label = 'query' this.bang = function (input = window.location.hash) { - var target = input.to_url() === '' ? 'home' : input.to_url() + let target = input.to_url() === '' ? 'home' : input.to_url() Ø('view').el.className = `${target.to_path()} loading` @@ -22,12 +22,12 @@ function QueryNode (id, rect) { } } -var detectBackOrForward = function (onBack, onForward) { +let detectBackOrForward = function (onBack, onForward) { hashHistory = [window.location.hash] historyLength = window.history.length return function () { - var hash = window.location.hash; var length = window.history.length + let hash = window.location.hash; let length = window.history.length if (hashHistory.length && historyLength == length) { if (hashHistory[hashHistory.length - 2] == hash) { hashHistory = hashHistory.slice(0, -1) diff --git a/scripts/nodes/router.js b/scripts/nodes/router.js @@ -4,10 +4,10 @@ function RouterNode (id, rect) { this.glyph = NODE_GLYPHS.router this.receive = function (q) { - var target = q.indexOf(':') > -1 ? q.split(':')[0].replace(/\+/g, ' ') : q.replace(/\+/g, ' ') - var params = q.indexOf(':') > -1 ? q.split(':')[1] : null - var db = this.request('database').database - var data = find(target.toUpperCase(), db) + let target = q.indexOf(':') > -1 ? q.split(':')[0].replace(/\+/g, ' ') : q.replace(/\+/g, ' ') + let params = q.indexOf(':') > -1 ? q.split(':')[1] : null + let db = this.request('database').database + let data = find(target.toUpperCase(), db) this.label = `${this.id}|${target}|${params}` @@ -26,7 +26,7 @@ function RouterNode (id, rect) { if (parseInt(key) > 0) { return null } for (id in db) { - var table = db[id] + let table = db[id] if (table[key]) { return { type: id, result: table[key] } } diff --git a/scripts/nodes/template.js b/scripts/nodes/template.js @@ -6,8 +6,8 @@ function TemplateNode (id, rect) { this.cache = null this.receive = function (q) { - var assoc = this.signal(q.type ? q.type.slice(0, -1) : 'page') - var payload = assoc.answer(q) + let assoc = this.signal(q.type ? q.type.slice(0, -1) : 'page') + let payload = assoc.answer(q) this.send(payload) this.label = `template:${assoc.id}` diff --git a/scripts/templates/home.js b/scripts/templates/home.js @@ -4,13 +4,13 @@ function HomeTemplate (id, rect) { this.glyph = NODE_GLYPHS.render this.answer = function (q) { - var ingredients = find_ingredients(q.tables.recipes) + let ingredients = find_ingredients(q.tables.recipes) ingredients['coffee'] = 1 - var sorted_ingredients = sort_ingredients(ingredients) + let sorted_ingredients = sort_ingredients(ingredients) - var html = ` + let html = ` ${make_ingredients(sorted_ingredients, q.tables.ingredients)} <h1>Recipes</h1> ${make_recipes(q.tables.recipes)} @@ -27,11 +27,11 @@ function HomeTemplate (id, rect) { } function find_ingredients (recipes) { - var h = {} + let h = {} for (id in recipes) { - var recipe = recipes[id] + let recipe = recipes[id] for (id in recipe.INGR) { - var category = recipe.INGR[id] + let category = recipe.INGR[id] for (name in category) { h[name] = h[name] ? h[name] + 1 : 1 } @@ -41,9 +41,9 @@ function HomeTemplate (id, rect) { } function sort_ingredients (ingredients) { - var a = [] + let a = [] for (name in ingredients) { - var value = ingredients[name] + let value = ingredients[name] a.push([name, value]) } a.sort(function (a, b) { @@ -53,9 +53,9 @@ function HomeTemplate (id, rect) { } function make_ingredients (ingredients, table) { - var html = '' + let html = '' for (id in ingredients) { - var name = ingredients[id][0] + let name = ingredients[id][0] html += ` <li class='ingredient ${!table[name] ? 'missing' : ''}'> <a href='#${name.to_url()}' onclick="Ø('query').bang('${name}')"> @@ -68,7 +68,7 @@ function HomeTemplate (id, rect) { } function count_ingredients (recipe) { - var ingredients = {} + let ingredients = {} for (cat in recipe.INGR) { for (id in recipe.INGR[cat]) { ingredients[id] = 1 @@ -78,25 +78,25 @@ function HomeTemplate (id, rect) { } function make_recipes (recipes) { - var html = '' + let html = '' // Sort by tag - var categorized = {} + let categorized = {} for (name in recipes) { - var recipe = recipes[name] + let recipe = recipes[name] if (!categorized[recipe.TAGS[0]]) { categorized[recipe.TAGS[0]] = [] } recipe.name = name categorized[recipe.TAGS[0]].push(recipe) } for (cat in categorized) { - var recipes = categorized[cat] + let recipes = categorized[cat] html += `<h3>${cat.capitalize()}</h3>` html += "<ul style='margin-bottom:15px'>" for (id in recipes) { - var recipe = recipes[id] + let recipe = recipes[id] html += `<li><a href="#${recipe.name.to_url()}" onclick="Ø('query').bang('${recipe.name.capitalize()}')">${recipe.name.capitalize()}</a></li>` } html += '</ul>' diff --git a/scripts/templates/ingredient.js b/scripts/templates/ingredient.js @@ -6,7 +6,7 @@ function IngredientTemplate (id, rect) { // Create the recipe body this.answer = function (t) { - var ingredient = t.result + let ingredient = t.result return { title: `GrimGrains — ${t.name.capitalize()}`, @@ -20,7 +20,7 @@ function IngredientTemplate (id, rect) { } function make_ingredient (name, ingredient, recipes) { - var html = '' + let html = '' html += `<h1>${ingredient.TYPE ? ingredient.TYPE.capitalize() + '/' : ''}${name.capitalize()}</h1>` html += ingredient.BREF ? `<p class='bref'>${ingredient.BREF.to_markup()}</p>` : '' @@ -30,13 +30,13 @@ function IngredientTemplate (id, rect) { } function make_similar (search_name, recipes) { - var html = '' - var ingredients = find_ingredients(recipes) - var similar_ingredients = find_similar_ingredients(search_name, ingredients) + let html = '' + let ingredients = find_ingredients(recipes) + let similar_ingredients = find_similar_ingredients(search_name, ingredients) for (id in similar_ingredients) { if (similar_ingredients[id][1] < 1) { break } - var name = similar_ingredients[id][0] + let name = similar_ingredients[id][0] if (name.toLowerCase() == search_name.toLowerCase()) { continue } html += ` <li class='ingredient'> @@ -50,11 +50,11 @@ function IngredientTemplate (id, rect) { } function find_ingredients (recipes) { - var h = {} + let h = {} for (id in recipes) { - var recipe = recipes[id] + let recipe = recipes[id] for (id in recipe.INGR) { - var category = recipe.INGR[id] + let category = recipe.INGR[id] for (name in category) { h[name] = h[name] ? h[name] + 1 : 1 } @@ -64,11 +64,11 @@ function IngredientTemplate (id, rect) { } function find_similar_ingredients (name, ingredients) { - var a = [] + let a = [] for (id in ingredients) { - var words = id.toLowerCase().split(' ') - var index = similarity(name.toLowerCase().split(' '), words) + let words = id.toLowerCase().split(' ') + let index = similarity(name.toLowerCase().split(' '), words) if (index > 0) { a.push([id, index]) } @@ -82,11 +82,11 @@ function IngredientTemplate (id, rect) { } function similarity (a, b) { - var score = 0 + let score = 0 for (a_id in a) { - var word_a = a[a_id] + let word_a = a[a_id] for (b_id in b) { - var word_b = b[b_id] + let word_b = b[b_id] score += word_a == word_b ? 1 : 0 } } @@ -94,12 +94,12 @@ function IngredientTemplate (id, rect) { } function make_related (recipes) { - var html = '' + let html = '' - var count = 0 + let count = 0 for (id in recipes) { - var recipe = recipes[id] - var name = id + let recipe = recipes[id] + let name = id html += ` <li class='recipe'> <a onclick="Ø('query').bang('${name}')" class='photo' href='#${name.to_url()}' style='background-image:url(media/recipes/${name.to_path()}.jpg)'></a> @@ -117,11 +117,11 @@ function IngredientTemplate (id, rect) { } function related_recipes (name, recipes) { - var h = {} + let h = {} for (id in recipes) { - var recipe = recipes[id] + let recipe = recipes[id] for (i in recipe.INGR) { - var ingredients = recipe.INGR[i] + let ingredients = recipe.INGR[i] for (n in ingredients) { if (n.indexOf(name.toUpperCase()) < 0) { continue } h[id] = recipes[id] @@ -132,9 +132,9 @@ function IngredientTemplate (id, rect) { } function related_ingredients (name, tag, ingredients) { - var a = [] + let a = [] for (id in ingredients) { - var ingredient = ingredients[id] + let ingredient = ingredients[id] if (!ingredient.TAGS || ingredient.TAGS.indexOf(tag) < 0 || id == name) { continue } a.push(id) } @@ -142,7 +142,7 @@ function IngredientTemplate (id, rect) { } function count_ingredients (recipe) { - var ingredients = {} + let ingredients = {} for (cat in recipe.INGR) { for (id in recipe.INGR[cat]) { ingredients[id] = 1 diff --git a/scripts/templates/page.js b/scripts/templates/page.js @@ -15,7 +15,7 @@ function PageTemplate (id, rect) { return this.signal('search').answer(q) } - var page = q.result + let page = q.result return { title: `GrimGrains — ${q.name.capitalize()}`, view: { @@ -27,7 +27,7 @@ function PageTemplate (id, rect) { } function list (items) { - var html = '' + let html = '' for (id in items) { html += `<li>${id} -> ${items[id]}</li>` // html += list(items[id]) diff --git a/scripts/templates/recipe.js b/scripts/templates/recipe.js @@ -21,8 +21,8 @@ function RecipeTemplate (id, rect) { } function make_content (q) { - var recipe = q.result - var html = '' + let recipe = q.result + let html = '' html += ` <h1 class='name'>${q.name.capitalize()}</h1> @@ -39,14 +39,14 @@ function RecipeTemplate (id, rect) { } function make_instructions (recipe) { - var html = '' + let html = '' html += `<h2>Instructions</h2>` - var count = 1 + let count = 1 for (cat in recipe.INST) { html += `<h3>Step ${count}: ${cat.capitalize()}</h3>` - var category = recipe.INST[cat].map(convertTemperatures) + let category = recipe.INST[cat].map(convertTemperatures) html += new Runic(category).toString() count += 1 } @@ -71,14 +71,14 @@ function RecipeTemplate (id, rect) { } function make_related (q) { - var html = '' - var recipe = q.result - var recipes = find_related(q.name, recipe, q.tables.recipes) + let html = '' + let recipe = q.result + let recipes = find_related(q.name, recipe, q.tables.recipes) - var count = 0 + let count = 0 for (id in recipes) { - var name = recipes[id][0] - var recipe = q.tables.recipes[name] + let name = recipes[id][0] + let recipe = q.tables.recipes[name] html += ` <li class='recipe'> <a class='photo' onclick="Ø('query').bang('${name}')" href='#${name.to_url()}' style='background-image:url(media/recipes/${name.to_path()}.jpg)'></a> @@ -92,7 +92,7 @@ function RecipeTemplate (id, rect) { } function count_ingredients (recipe) { - var ingredients = {} + let ingredients = {} for (cat in recipe.INGR) { for (id in recipe.INGR[cat]) { ingredients[id] = 1 @@ -102,10 +102,10 @@ function RecipeTemplate (id, rect) { } function find_related (name, target, recipes) { - var a = [] + let a = [] for (id in recipes) { - var recipe = recipes[id] - var index = similarity(target.TAGS, recipe.TAGS) + let recipe = recipes[id] + let index = similarity(target.TAGS, recipe.TAGS) if (id.toLowerCase() != name.toLowerCase()) { a.push([id, index]) } @@ -117,14 +117,14 @@ function RecipeTemplate (id, rect) { } function make_ingredients (categories) { - var html = '' + let html = '' for (id in categories) { - var elements = categories[id] + let elements = categories[id] html += `<ul class='ingredients'>` html += Object.keys(categories).length > 1 ? `<h3>${id.capitalize()}</h3>` : '' for (name in elements) { - var element = elements[name] + let element = elements[name] html += ` <li class='ingredient'> <a onclick="Ø('query').bang('${name}')" href='#${name.to_url()}'> @@ -140,11 +140,11 @@ function RecipeTemplate (id, rect) { } function similarity (a, b) { - var score = 0 + let score = 0 for (a_id in a) { - var tag_a = a[a_id] + let tag_a = a[a_id] for (b_id in b) { - var tag_b = b[b_id] + let tag_b = b[b_id] score += tag_a.toLowerCase() == tag_b.toLowerCase() ? 1 : 0 } } diff --git a/scripts/templates/search.js b/scripts/templates/search.js @@ -6,7 +6,7 @@ function SearchTemplate (id, rect) { // Create the search body this.answer = function (q) { - var html = '' + let html = '' return { title: `GrimGrains — Search`, @@ -23,7 +23,7 @@ function SearchTemplate (id, rect) { } function make_content (q) { - var html = '' + let html = '' const index = Object.keys(q.tables.ingredients).concat(Object.keys(q.tables.recipes)) const similar = findSimilar(q.name.toUpperCase(), index)