jekyll-theme-recipe 0.2.1 → 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: 112c9ca0e9547ea9de6ce31accdccdcc2721a7ab9c0862ec98bb74c43940bd9a
4
- data.tar.gz: ca80c8304ad842d2c0770e2c2d16ced1a51fa634a1fcb6baad3730ddf006a77d
3
+ metadata.gz: 90126dd2683254dcfd339a4190d74384fa543e0ed1fc533d70b9c8c88655758b
4
+ data.tar.gz: 3b4a8941d51a9d0ac84673896ab224b30085d8ebbf9f4a38839b3e6111e556ed
5
5
  SHA512:
6
- metadata.gz: d111ff230a2d1bb486824405ab412d37cac631b2d8f0b33c20fc359eea5aad22fddf250d18f09df08520697112ceaebf4cf4f768ab5b50aad20c4ae4afb010af
7
- data.tar.gz: cddad8da43fb408d0bd17aa1d53be04869134de3daf58c2289aa7309f3dad0fe3f6e77ef957ad9f00fe28e2348faa25e4d0f29788110c9b1d54398055ad5ecf1
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 {
data/_sass/fonts.scss CHANGED
@@ -1,21 +1,21 @@
1
1
  @font-face {
2
2
  font-family: "Atkinson Hyperlegible";
3
- src: url("../assets/fonts/AtkinsonHyperlegible-Regular.ttf");
3
+ src: url("../fonts/AtkinsonHyperlegible-Regular.ttf");
4
4
  font-weight: normal;
5
5
  }
6
6
  @font-face {
7
7
  font-family: "Atkinson Hyperlegible";
8
- src: url("../assets/fonts/AtkinsonHyperlegible-Bold.ttf");
8
+ src: url("../fonts/AtkinsonHyperlegible-Bold.ttf");
9
9
  font-weight: bold;
10
10
  }
11
11
  @font-face {
12
12
  font-family: "Atkinson Hyperlegible";
13
- src: url("../assets/fonts/AtkinsonHyperlegible-Italic.ttf");
13
+ src: url("../fonts/AtkinsonHyperlegible-Italic.ttf");
14
14
  font-style: italic;
15
15
  }
16
16
  @font-face {
17
17
  font-family: "Atkinson Hyperlegible";
18
- src: url("../assets/fonts/AtkinsonHyperlegible-BoldItalic.ttf");
18
+ src: url("../fonts/AtkinsonHyperlegible-BoldItalic.ttf");
19
19
  font-weight: bold;
20
20
  font-style: italic;
21
21
 
@@ -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.1
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