jekyll-theme-recipe 0.2.2 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/_layouts/post.html +5 -3
- data/_sass/blog.scss +27 -0
- data/assets/js/servings.js +62 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6415f1dd68e7846527bdc5801317eef3952cf0859e1f41c50feb8124bdf2225e
|
4
|
+
data.tar.gz: c41ac1b25dbaff9593c47422529fcf5d328b984d0302395f40806b1fef52081f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30442ecc573dd4f02edb776ff21fa5602bedede639579ec2ca8e8e9e6f4dcc87b63dfb9b65b3b73a627c9b423832c1832d2404887c34d9c778f210aa45a0dfc3
|
7
|
+
data.tar.gz: ad899846b9563972b3bc747ce47ffabaec2748f1bdab148e5967d59447c24ae1a5490ac902b81070e638387c0c0bb6b4e9966505e3afb034cb3d8b9dafd5bc13
|
data/_layouts/post.html
CHANGED
@@ -12,7 +12,10 @@ layout: default
|
|
12
12
|
</div>
|
13
13
|
|
14
14
|
<ul id="recipe" class="recipe-overview">
|
15
|
-
<li title="Servings">{% include recipe-icon.html icon="quantity" %}<span>
|
15
|
+
<li title="Servings">{% include recipe-icon.html icon="quantity" %}<span>
|
16
|
+
<input id="servings_number" type="number" min="1" value="{{ page.recipe.servings }}">
|
17
|
+
<label for="servings_number">{{ page.recipe.servings_name }}</label>
|
18
|
+
</span></li>
|
16
19
|
<li title="Prep Time">{% include recipe-icon.html icon="time" %}<span>{{ page.recipe.prep }}</span></li>
|
17
20
|
<li title="Cook Time">{% include recipe-icon.html icon="cook" %}<span>{{ page.recipe.cook }}</span></li>
|
18
21
|
</ul>
|
@@ -66,8 +69,7 @@ layout: default
|
|
66
69
|
{% endif %}
|
67
70
|
</article>
|
68
71
|
|
69
|
-
<script type="text/javascript" src="
|
70
|
-
<script type="text/javascript" src="{{ site.baseurl }}/assets/js/jquery.imgPin.min.js"></script>
|
72
|
+
<script type="text/javascript" src="{{ site.baseurl }}/assets/js/servings.js"></script>
|
71
73
|
<script>
|
72
74
|
$(function() {
|
73
75
|
$('.post img').imgPin();
|
data/_sass/blog.scss
CHANGED
@@ -34,6 +34,29 @@
|
|
34
34
|
display: inline-block;
|
35
35
|
}
|
36
36
|
}
|
37
|
+
|
38
|
+
input[type="number"] {
|
39
|
+
max-width: 50px;
|
40
|
+
|
41
|
+
background-color: black;
|
42
|
+
color: white;
|
43
|
+
border: none;
|
44
|
+
padding: 4px;
|
45
|
+
|
46
|
+
box-sizing: border-box;
|
47
|
+
|
48
|
+
&:hover, &:active, &:focus {
|
49
|
+
background-color: initial;
|
50
|
+
color: initial;
|
51
|
+
|
52
|
+
border: 1px solid black;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
label {
|
57
|
+
display: initial;
|
58
|
+
cursor: pointer;
|
59
|
+
}
|
37
60
|
}
|
38
61
|
|
39
62
|
.recipe-contents {
|
@@ -41,6 +64,10 @@
|
|
41
64
|
display: flex;
|
42
65
|
}
|
43
66
|
|
67
|
+
p {
|
68
|
+
margin-bottom: 0;
|
69
|
+
}
|
70
|
+
|
44
71
|
// ingredients
|
45
72
|
tr {
|
46
73
|
vertical-align: top;
|
@@ -0,0 +1,62 @@
|
|
1
|
+
const portionElements = document.querySelectorAll('tr > td:first-child');
|
2
|
+
|
3
|
+
const portionInput = document.querySelector('input#servings_number');
|
4
|
+
var currentPortion = portionInput.value;
|
5
|
+
portionInput.addEventListener("change", calculateServings);
|
6
|
+
|
7
|
+
function calculateServings(){
|
8
|
+
const newPortion = portionInput.value;
|
9
|
+
|
10
|
+
for (var i = 0; i < portionElements.length; i++) {
|
11
|
+
if(portionElements[i].innerHTML == " "){ // " " == empty space
|
12
|
+
continue; // no portion specified
|
13
|
+
}
|
14
|
+
|
15
|
+
const portionElementValue = portionElements[i].innerHTML.search('/') >=0
|
16
|
+
? fractionToDecimal(portionElements[i].innerHTML)
|
17
|
+
: Number.parseFloat(portionElements[i].innerHTML);
|
18
|
+
|
19
|
+
const newPortionValue = trimNumberAfterDecimalPoint(portionElementValue * newPortion / currentPortion, 3);
|
20
|
+
|
21
|
+
const newPortionString = newPortionValue.toString();
|
22
|
+
portionElements[i].innerHTML = newPortionString.includes('.')
|
23
|
+
? decimalToFraction(newPortionString)
|
24
|
+
: newPortionString;
|
25
|
+
}
|
26
|
+
|
27
|
+
currentPortion = newPortion;
|
28
|
+
}
|
29
|
+
|
30
|
+
// from: http://jsfiddle.net/5QrhQ/5/ or https://stackoverflow.com/a/23575406
|
31
|
+
function decimalToFraction(decimal){
|
32
|
+
var len = decimal.toString().length - 2;
|
33
|
+
|
34
|
+
var denominator = Math.pow(10, len);
|
35
|
+
var numerator = decimal * denominator;
|
36
|
+
|
37
|
+
var divisor = gcd(numerator, denominator);
|
38
|
+
|
39
|
+
numerator /= divisor;
|
40
|
+
denominator /= divisor;
|
41
|
+
|
42
|
+
return Math.floor(numerator) + '/' + Math.floor(denominator);
|
43
|
+
}
|
44
|
+
function gcd(a, b) {
|
45
|
+
if (b < 0.0000001) return a; // Since there is a limited precision we need to limit the value.
|
46
|
+
|
47
|
+
return gcd(b, Math.floor(a % b)); // Discard any fractions due to limitations in precision.
|
48
|
+
};
|
49
|
+
|
50
|
+
|
51
|
+
// from https://stackoverflow.com/a/49246271
|
52
|
+
function fractionToDecimal(fraction) {
|
53
|
+
return fraction
|
54
|
+
.split('/')
|
55
|
+
.reduce((numerator, denominator, i) =>
|
56
|
+
numerator / (i ? denominator : 1)
|
57
|
+
);
|
58
|
+
}
|
59
|
+
|
60
|
+
function trimNumberAfterDecimalPoint(number, decimals){
|
61
|
+
return Math.round(number * Math.pow(10, decimals)) / Math.pow(10, decimals);
|
62
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-theme-recipe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hanno Witzleb
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -164,6 +164,7 @@ files:
|
|
164
164
|
- assets/images/favicon.png
|
165
165
|
- assets/images/logo.svg
|
166
166
|
- assets/js/jquery.imgPin.min.js
|
167
|
+
- assets/js/servings.js
|
167
168
|
homepage: https://github.com/Xipit/jekyll-theme-recipe
|
168
169
|
licenses:
|
169
170
|
- CC0-1.0
|