jekyll-theme-recipe 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c9178f7e12bcfd1c2b50c6f1d7bafa8cf1125652284bb0a6e444af0d4ba913d
4
- data.tar.gz: 54fa94c51ce22a956ac3ab0ea1e0aa4a49b3bc54476847edb2ad12fb0af20a01
3
+ metadata.gz: 90126dd2683254dcfd339a4190d74384fa543e0ed1fc533d70b9c8c88655758b
4
+ data.tar.gz: 3b4a8941d51a9d0ac84673896ab224b30085d8ebbf9f4a38839b3e6111e556ed
5
5
  SHA512:
6
- metadata.gz: af516cb7a8d32d6e49af0322185dd336b035b3c721f946a6e2708f795a1bd5c52a1284aa25a8a2d5144b1a42e9b294739ae343d70a6f17f9983b844cdb53e18b
7
- data.tar.gz: 16470ae2adb286bfafce2a4a86fb41dad5fc955d74c03744fcb88a88a3279ebd94cd803ece55a45fce91e67742065ccaaa55e373155d31c393ba815b3e6a7a5d
6
+ metadata.gz: 514d2e282a5d58ff21820c0307904291a311d99129293a7633799550bddce2b2bce5048ea30fe8c048d2ef68417d77d22032b4f08ab3e99860fe6b243cebac73
7
+ data.tar.gz: af5542f6a637db3a3c7d31670f57f1c1e0d88c17d660a0efe4236ce1b04b9b3fbd1b2c900cd60df24cbd8d0e90dbf355ac4b6d1b775d9241af3c0a37830e6421
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>{{ page.recipe.servings }}</span></li>
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="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
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 {
@@ -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 == "&nbsp;"){ // "&nbsp;" == 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.2.2
4
+ version: 0.3.0
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-12 00:00:00.000000000 Z
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
@@ -183,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
184
  - !ruby/object:Gem::Version
184
185
  version: '0'
185
186
  requirements: []
186
- rubygems_version: 3.3.26
187
+ rubygems_version: 3.4.6
187
188
  signing_key:
188
189
  specification_version: 4
189
190
  summary: Recipe is a Jekyll theme for recipe websites, and adapted from CloudCannons