-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As implemented in clarklab/chowdown#39, extended to include total and active time.
- Loading branch information
Showing
10 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{% assign thisRecipe = include.recipe %} | ||
<div class="center ml2 mr2"> | ||
{% if thisRecipe.preptime %} | ||
<div class="inline-block xs-m1 sm-m2"> | ||
<svg class="gray align-middle" xmlns="http://www.w3.org/2000/svg" width="1.5rem" height="1.5rem" viewBox="0 0 512 512" fill="currentColor"><circle cx="256" cy="256" r="256"/><rect x="246.21" y="52.09" width="19.58" height="214.26" rx="9.79" fill="#fff"/><rect x="290.06" y="228.55" width="19.58" height="143.63" rx="9.79" transform="translate(724.26 300.72) rotate(135)" fill="#fff"/></svg> | ||
<span class="blue caps align-middle">Prep</span> | ||
<span class="nowrap align-middle" id="prepTime_{{ thisRecipe.id }}" data-iso8601="{{ thisRecipe.preptime | upcase }}"></span> | ||
</div> | ||
<meta itemprop="prepTime" content="{{ thisRecipe.preptime | upcase }}"> | ||
{% endif %} | ||
{% if thisRecipe.cooktime %} | ||
<div class="inline-block xs-m1 sm-m2"> | ||
<svg class="gray align-middle" xmlns="http://www.w3.org/2000/svg" width="1.5rem" height="1.5rem" viewBox="0 0 512 512" fill="currentColor"><circle cx="256" cy="256" r="256"/><rect x="246.21" y="52.09" width="19.58" height="214.26" rx="9.79" fill="#fff"/><rect x="290.06" y="228.55" width="19.58" height="143.63" rx="9.79" transform="translate(724.26 300.72) rotate(135)" fill="#fff"/></svg> | ||
<span class="h4 blue caps align-middle">Cook</span> | ||
<span class="nowrap align-middle" id="cookTime_{{ thisRecipe.id }}" data-iso8601="{{ thisRecipe.cooktime | upcase }}"></span> | ||
</div> | ||
<meta itemprop="cookTime" content="{{ thisRecipe.cooktime | upcase }}"> | ||
{% endif %} | ||
{% if thisRecipe.totaltime %} | ||
<div class="inline-block xs-m1 sm-m2"> | ||
<svg class="gray align-middle" xmlns="http://www.w3.org/2000/svg" width="1.5rem" height="1.5rem" viewBox="0 0 512 512" fill="currentColor"><circle cx="256" cy="256" r="256"/><rect x="246.21" y="52.09" width="19.58" height="214.26" rx="9.79" fill="#fff"/><rect x="290.06" y="228.55" width="19.58" height="143.63" rx="9.79" transform="translate(724.26 300.72) rotate(135)" fill="#fff"/></svg> | ||
<span class="h4 blue caps align-middle">Total</span> | ||
<span class="nowrap align-middle" id="totalTime_{{ thisRecipe.id }}" data-iso8601="{{ thisRecipe.totaltime | upcase }}"></span> | ||
</div> | ||
<meta itemprop="totalTime" content="{{ thisRecipe.totaltime | upcase }}"> | ||
{% endif %} | ||
{% if thisRecipe.activetime %} | ||
<div class="inline-block xs-m1 sm-m2"> | ||
<svg class="gray align-middle" xmlns="http://www.w3.org/2000/svg" width="1.5rem" height="1.5rem" viewBox="0 0 512 512" fill="currentColor"><circle cx="256" cy="256" r="256"/><rect x="246.21" y="52.09" width="19.58" height="214.26" rx="9.79" fill="#fff"/><rect x="290.06" y="228.55" width="19.58" height="143.63" rx="9.79" transform="translate(724.26 300.72) rotate(135)" fill="#fff"/></svg> | ||
<span class="h4 blue caps align-middle">Active</span> | ||
<span class="nowrap align-middle" id="activeTime_{{ thisRecipe.id }}" data-iso8601="{{ thisRecipe.activetime | upcase }}"></span> | ||
</div> | ||
{% endif %} | ||
</div> | ||
{% assign thisRecipe = nil %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
let en_GB = { | ||
map: {Y: 'yr', B: 'mth', W: 'wk', D: 'day', H: 'hr', M: 'min', S: 'sec'}, | ||
counted: function(i, c){ | ||
res = this.map[i]; | ||
if(c > 1) { res += 's' } | ||
return res; | ||
} | ||
}; | ||
|
||
function Duration(el) { | ||
this.element = document.getElementById(el); | ||
this.lang = en_GB; | ||
this.result = { Y: 0, B: 0, W: 0, D: 0, H: 0, M: 0, S: 0 }; | ||
this._rex = /(\d+(?:\.\d+)?)([YBWDHMS])/ig; | ||
this.parts = function () { | ||
let iso8601 = this.element.dataset.iso8601; | ||
let parts = iso8601.substr(1).replace(/M(.*?)T/, 'B$1'); | ||
parts.match(this._rex).forEach((p) => { | ||
let scale = p.substring(0, p.length - 1); | ||
let unit = p.substring(p.length - 1).toUpperCase(); | ||
this.result[unit] = Number(scale); | ||
}); | ||
return this.result; | ||
}; | ||
this.format = function () { | ||
const nonZero = (v) => v > 0; | ||
let words = []; | ||
let parts = this.parts(); | ||
for (var p in parts) { | ||
if (parts.hasOwnProperty(p) && nonZero(parts[p])) { | ||
words.push(`${parts[p]} ${this.lang.counted(p, parts[p])}`); | ||
} | ||
} | ||
return words.join(' '); | ||
}; | ||
this.update = function () { | ||
this.element.innerHTML = this.format(); | ||
}; | ||
} | ||
|
||
/* | ||
Update the page either via object calls passing in the dom ID: | ||
new Duration('prepTime').update(); | ||
new Duration('cookTime').update(); | ||
or use jquery to find them: | ||
$('*[data-iso8601]').each(function (){ | ||
new Duration(this.id).update(); | ||
}); | ||
*/ | ||
$('*[data-iso8601]').each(function (){ | ||
new Duration(this.id).update(); | ||
}); |
6b68d86
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @foosel, good idea! I think I'll update my original PR to include schema's 'totalTime' too. 👍
6b68d86
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, happy to inspire 🙂