diff --git a/docs/bitty.js b/docs/bitty.js index 72fdfc0..cb224bb 100644 --- a/docs/bitty.js +++ b/docs/bitty.js @@ -141,8 +141,15 @@ class DataURL { compressedData = encryptedData } - var base64String = dataToBase64(compressedData); - base64String = base64String.replace(/=+$/, ""); + var base64String + try { + base64String = dataToBase64(compressedData); + } catch (e) { + console.log("dataToBase64FR used:", e); + base64String = await dataToBase64FR(compressedData); + } + + // base64String = base64String.replace(/=+$/, ""); this.data = base64String; this.params.format = format; @@ -256,7 +263,8 @@ async function compressDataGzip(data) { if (typeof CompressionStream !== 'undefined') { let blob = new Blob([data]) const stream = blob.stream().pipeThrough(new CompressionStream("gzip")); - let respose = await new Response (stream).arrayBuffer().catch(e => {console.error("CompressionStream error", e)}) + let response = await new Response (stream).arrayBuffer().catch(e => {console.error("CompressionStream error", e)}) + if (response) return response } return import("/js/gzip/pako.min.js").then((module) => { diff --git a/docs/render/parse.js b/docs/render/parse.js index a0839c7..331fdb4 100644 --- a/docs/render/parse.js +++ b/docs/render/parse.js @@ -34,6 +34,8 @@ function findMicrodataRecipe(doc) { return parseMicrodata(doc).find((item)=>item["@type"]=="Recipe"); } + + let scrapeRecipe = async document => { // Get title @@ -128,11 +130,17 @@ let scrapeRecipe = async document => { let recipe = findLDJsonRecipe(doc) || findMicrodataRecipe(doc) || await scrapeRecipe(doc); if (!recipe.recipeInstructions) recipe = undefined; + if (recipe) { let url = doc.evaluate('//meta[@property="og:url"]/@content', doc, null, XPathResult.STRING_TYPE)?.stringValue; if (url) recipe.mainEntityOfPage = url + if (!recipe.image) { + recipe.image = doc.evaluate('//meta[@property="og:image"]/@content', doc, null, XPathResult.STRING_TYPE)?.stringValue; + } + + console.log(recipe); let f = new FileReader(); f.onload = function(e) { parent.postMessage({replaceURL:e.target.result, compressURL:"true"}, "*"); @@ -143,8 +151,6 @@ if (recipe) { } - - function parseMicrodata(doc) { let parsedElements = [] const microdata = []; diff --git a/docs/render/recipe.css b/docs/render/recipe.css index d5d23a6..a02161c 100644 --- a/docs/render/recipe.css +++ b/docs/render/recipe.css @@ -18,6 +18,7 @@ body { var(--hover-background-color); --background-color:white; --accent-color:#D42A20; + --highlight-color:#FAC22B; } .thumbnail { @@ -151,7 +152,7 @@ h1 { font-size: 2em; } .noun.hovered { - background-color:#FAC22B; + background-color:var(--highlight-color); padding:0px 2px 2px 2px; margin:-0px -2px -2px -2px; border-radius:2px; @@ -163,7 +164,7 @@ background-color:#f1f1f1; } .ingredient.hovered { - background-color: #FAC22B; + background-color: var(--highlight-color); } .metadata { display: flex; @@ -242,9 +243,9 @@ span.bullet { .complete span.bullet, li:hover span.bullet { color:transparent; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='48' width='48'%3E%3Cpath d='M18.9 36.9 6.5 24.5 9.9 21.1 18.9 30.1 38.05 10.95 41.45 14.35Z'/%3E%3C/svg%3E"); background-size:cover; - } - .complete span.number { + +.complete span.number { border-color:transparent; } @@ -279,7 +280,7 @@ li { } .ingredient:hover, li:hover { - background-color:rgba(0,0,0,0.1); + background-color:var(--hover-background-color) } .spacer { @@ -686,7 +687,12 @@ img.qr { --background-color:#222; --disabled-text-color: rgba(255,255,255, 0.54); - --accent-color:rgba(255,255,255, 0.7); + --accent-color:rgb(255, 159, 159); + --highlight-color:#eaa000b6; + } + + .complete span.bullet, li:hover span.bullet { + background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='white' height='48' width='48'%3E%3Cpath d='M18.9 36.9 6.5 24.5 9.9 21.1 18.9 30.1 38.05 10.95 41.45 14.35Z'/%3E%3C/svg%3E"); background-size:cover; } } diff --git a/docs/render/recipe.js b/docs/render/recipe.js index 2903d32..35c074c 100644 --- a/docs/render/recipe.js +++ b/docs/render/recipe.js @@ -1,8 +1,11 @@ let reformat = true; let FRACTION_MAP = { + '0.25': '\u00BC', '1/4': '\u00BC', + '0.5': '\u00BD', '1/2': '\u00BD', + '0.75': '\u00BE', '3/4': '\u00BE', '1/3': '\u2153', '2/3': '\u2154', @@ -17,7 +20,7 @@ let FRACTION_MAP = { '5/8': '\u215D', '7/8': '\u215E', replace: function(string) { - return string.replace(/\d\/\d/g, function(a, b, c) { + return string.replace(/\d[\/\.]\d\d?/g, function(a, b, c) { return FRACTION_MAP[a]; }) } @@ -166,14 +169,13 @@ let emojiMap = { let icons = { public:(''), share_android:(''), - share:(` - - `), + share:(``), print:(``), checklist:(''), servings:(''), timer:(''), - rating:('') + rating:(''), + info:('') } const replacements = { @@ -322,7 +324,7 @@ function highlightStep(e) { } -const ingredientMatch = /^(?:A )?([\-\/0-9 \u00BC-\u00BE\u2153-\u215E\u2009]*)\s(.*)/ +const ingredientMatch = /^(?:A )?([\-\/0-9\. \u00BC-\u00BE\u2153-\u215E\u2009]*)\s(.*)/ function ingredientEl(string, terms) { @@ -434,7 +436,7 @@ function render() { } var json = r || JSON.parse(window.params.body) - console.log("🍗 Rendering Recipe:", json, JSON.parse(window.params.body)); + console.log("🍗 Rendering Recipe:", json); } catch (e) { @@ -462,7 +464,7 @@ function render() { parent.postMessage({title:title, favicon:favicon, image:image, description:description, wakeLock:true, updateURL:true}, "*"); description = description?.split("\n").join("
") // let text = instructions.join(" "); - let ingredients = json.recipeIngredient; + let ingredients = json.recipeIngredient || json.ingredients; var ingredientTerms = new Set( Array.from(ingredients.join("\n").matchAll(/(\p{L}\p{M}?)+/gu)).map(m => m[0].length > 2 ? m[0].toLowerCase(): "")