From fbf91d6e73ef8a7f2effc015c845a369026f26bf Mon Sep 17 00:00:00 2001 From: Rue Turner Date: Tue, 25 Feb 2020 17:11:45 +0000 Subject: [PATCH 01/10] add recipe timings and related schema microformats --- _includes/timings.html | 16 ++++++++++++++++ _layouts/recipe.html | 1 + _plugins/Duration.rb | 12 ++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 _includes/timings.html create mode 100644 _plugins/Duration.rb diff --git a/_includes/timings.html b/_includes/timings.html new file mode 100644 index 000000000..37929bb5b --- /dev/null +++ b/_includes/timings.html @@ -0,0 +1,16 @@ +
+ {% if page.preptime %} +
+ + Prep {{page.preptime | humanize_duration}} + +
+ {% endif %} + {% if page.cooktime %} +
+ + Cook {{page.cooktime | humanize_duration}} + +
+ {% endif %} +
diff --git a/_layouts/recipe.html b/_layouts/recipe.html index 33426a7e0..a5a9a7870 100644 --- a/_layouts/recipe.html +++ b/_layouts/recipe.html @@ -22,6 +22,7 @@

{{ page.title }}

+ {% include timings.html %}
diff --git a/_plugins/Duration.rb b/_plugins/Duration.rb new file mode 100644 index 000000000..52a0b9ca9 --- /dev/null +++ b/_plugins/Duration.rb @@ -0,0 +1,12 @@ +require 'active_support' +require 'active_support/duration' + +module Jekyll + module Duration + def humanize_duration(isoduration) + ActiveSupport::Duration.parse(isoduration).inspect + end + end +end + +Liquid::Template.register_filter(Jekyll::Duration) From 9e2708d5dcb2ac35dd55feada939f17e6874ba1e Mon Sep 17 00:00:00 2001 From: Rue Turner Date: Wed, 26 Feb 2020 10:22:28 +0000 Subject: [PATCH 02/10] Add basic gemfile / .gitignore --- .gitignore | 11 ++++++-- Gemfile | 9 ++++++ Gemfile.lock | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 Gemfile create mode 100644 Gemfile.lock diff --git a/.gitignore b/.gitignore index 5b18b54a8..06423a739 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,10 @@ /.c9 -/_site/ -/.jekyll-cache/ +# Ignore metadata generated by Jekyll +_site/ +.sass-cache/ +.jekyll-cache/ +.jekyll-metadata + +# Ignore folders generated by Bundler +.bundle/ +vendor/ diff --git a/Gemfile b/Gemfile new file mode 100644 index 000000000..2c5f18b4c --- /dev/null +++ b/Gemfile @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } + +gem "jekyll", "~> 4.0" + +gem "activesupport" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 000000000..3570ea8c0 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,77 @@ +GEM + remote: https://rubygems.org/ + specs: + activesupport (6.0.2.1) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + zeitwerk (~> 2.2) + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) + colorator (1.1.0) + concurrent-ruby (1.1.6) + em-websocket (0.5.1) + eventmachine (>= 0.12.9) + http_parser.rb (~> 0.6.0) + eventmachine (1.2.7) + ffi (1.12.2) + forwardable-extended (2.6.0) + http_parser.rb (0.6.0) + i18n (1.8.2) + concurrent-ruby (~> 1.0) + jekyll (4.0.0) + addressable (~> 2.4) + colorator (~> 1.0) + em-websocket (~> 0.5) + i18n (>= 0.9.5, < 2) + jekyll-sass-converter (~> 2.0) + jekyll-watch (~> 2.0) + kramdown (~> 2.1) + kramdown-parser-gfm (~> 1.0) + liquid (~> 4.0) + mercenary (~> 0.3.3) + pathutil (~> 0.9) + rouge (~> 3.0) + safe_yaml (~> 1.0) + terminal-table (~> 1.8) + jekyll-sass-converter (2.1.0) + sassc (> 2.0.1, < 3.0) + jekyll-watch (2.2.1) + listen (~> 3.0) + kramdown (2.1.0) + kramdown-parser-gfm (1.1.0) + kramdown (~> 2.0) + liquid (4.0.3) + listen (3.2.1) + rb-fsevent (~> 0.10, >= 0.10.3) + rb-inotify (~> 0.9, >= 0.9.10) + mercenary (0.3.6) + minitest (5.14.0) + pathutil (0.16.2) + forwardable-extended (~> 2.6) + public_suffix (4.0.3) + rb-fsevent (0.10.3) + rb-inotify (0.10.1) + ffi (~> 1.0) + rouge (3.16.0) + safe_yaml (1.0.5) + sassc (2.2.1) + ffi (~> 1.9) + terminal-table (1.8.0) + unicode-display_width (~> 1.1, >= 1.1.1) + thread_safe (0.3.6) + tzinfo (1.2.6) + thread_safe (~> 0.1) + unicode-display_width (1.6.1) + zeitwerk (2.2.2) + +PLATFORMS + ruby + +DEPENDENCIES + activesupport + jekyll (~> 4.0) + +BUNDLED WITH + 2.1.4 From ae30635256d7b325c72c28c50cd30bc1041aa6df Mon Sep 17 00:00:00 2001 From: Rue Turner Date: Fri, 28 Feb 2020 09:14:09 +0000 Subject: [PATCH 03/10] Put timings in component recipes --- _includes/timings.html | 17 +++++++++-------- _layouts/recipe.html | 2 ++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/_includes/timings.html b/_includes/timings.html index 37929bb5b..b4062f2e6 100644 --- a/_includes/timings.html +++ b/_includes/timings.html @@ -1,16 +1,17 @@ +{% assign recipe = include.recipe | default:recipe.recipe %}
- {% if page.preptime %} -
+ {% if recipe.preptime %} +
- Prep {{page.preptime | humanize_duration}} - + Prep {{ recipe.preptime | humanize_duration }} +
{% endif %} - {% if page.cooktime %} -
+ {% if recipe.cooktime %} +
- Cook {{page.cooktime | humanize_duration}} - + Cook {{ recipe.cooktime | humanize_duration }} +
{% endif %}
diff --git a/_layouts/recipe.html b/_layouts/recipe.html index a5a9a7870..575ed398c 100644 --- a/_layouts/recipe.html +++ b/_layouts/recipe.html @@ -101,6 +101,8 @@

{{recipe.title}}

{% endif %} {% endfor %} + {% include timings.html recipe=recipe %} +

{{ site.translation[site.language].ingredients }}

    {% for item in recipe.ingredients %} From 8a4c2b891514eca6232da9eafe6c4c0805ef0917 Mon Sep 17 00:00:00 2001 From: Rue Turner Date: Fri, 28 Feb 2020 10:32:10 +0000 Subject: [PATCH 04/10] handle lowercase designators --- _plugins/Duration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_plugins/Duration.rb b/_plugins/Duration.rb index 52a0b9ca9..a66d9b87a 100644 --- a/_plugins/Duration.rb +++ b/_plugins/Duration.rb @@ -4,7 +4,7 @@ module Jekyll module Duration def humanize_duration(isoduration) - ActiveSupport::Duration.parse(isoduration).inspect + ActiveSupport::Duration.parse(isoduration.upcase).inspect end end end From ff08c88fa083f7152b8b6517bd10505b86ca4839 Mon Sep 17 00:00:00 2001 From: Rue Turner Date: Thu, 30 Apr 2020 11:06:42 +0100 Subject: [PATCH 05/10] Add prepTime and cookTime supprt Wholly via javascript with no dependencies. This allows for it to be fully compatible with gh_pages --- _includes/timings.html | 6 +++--- _layouts/recipe.html | 3 ++- js/duration.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 js/duration.js diff --git a/_includes/timings.html b/_includes/timings.html index b4062f2e6..eedb1c5de 100644 --- a/_includes/timings.html +++ b/_includes/timings.html @@ -1,16 +1,16 @@ -{% assign recipe = include.recipe | default:recipe.recipe %} +{% assign recipe = include.recipe %}
    {% if recipe.preptime %}
    - Prep {{ recipe.preptime | humanize_duration }} + Prep
    {% endif %} {% if recipe.cooktime %}
    - Cook {{ recipe.cooktime | humanize_duration }} + Cook
    {% endif %} diff --git a/_layouts/recipe.html b/_layouts/recipe.html index 575ed398c..60a4f19fe 100644 --- a/_layouts/recipe.html +++ b/_layouts/recipe.html @@ -22,7 +22,7 @@

    {{ page.title }}

    - {% include timings.html %} + {% include timings.html recipe=page %}
    @@ -160,3 +160,4 @@

    {{ site.translation[site.language].directions }); + diff --git a/js/duration.js b/js/duration.js new file mode 100644 index 000000000..56b6e2640 --- /dev/null +++ b/js/duration.js @@ -0,0 +1,42 @@ +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(); + }; +} + +new Duration('prepTime').update(); +new Duration('cookTime').update(); From 0c4946841b3170c1db87eed6308c4e2e342d4dec Mon Sep 17 00:00:00 2001 From: Rue Turner Date: Thu, 30 Apr 2020 11:06:42 +0100 Subject: [PATCH 06/10] Add prepTime and cookTime supprt Wholly via javascript with no dependencies. This allows for it to be fully compatible with gh_pages --- _includes/timings.html | 27 ++++++++++++---------- _layouts/recipe.html | 3 ++- css/main.scss | 1 + js/duration.js | 52 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 13 deletions(-) create mode 100644 js/duration.js diff --git a/_includes/timings.html b/_includes/timings.html index b4062f2e6..82f7cc50c 100644 --- a/_includes/timings.html +++ b/_includes/timings.html @@ -1,17 +1,20 @@ -{% assign recipe = include.recipe | default:recipe.recipe %} -
    - {% if recipe.preptime %} -
    - - Prep {{ recipe.preptime | humanize_duration }} - +{% assign thisRecipe = include.recipe %} +
    + {% if thisRecipe.preptime %} +
    + + Prep +
    + {% endif %} - {% if recipe.cooktime %} -
    - - Cook {{ recipe.cooktime | humanize_duration }} - + {% if thisRecipe.cooktime %} +
    + + Cook +
    + {% endif %}
    +{% assign thisRecipe = nil %} diff --git a/_layouts/recipe.html b/_layouts/recipe.html index 575ed398c..60a4f19fe 100644 --- a/_layouts/recipe.html +++ b/_layouts/recipe.html @@ -22,7 +22,7 @@

    {{ page.title }}

    - {% include timings.html %} + {% include timings.html recipe=page %}
    @@ -160,3 +160,4 @@

    {{ site.translation[site.language].directions }); + diff --git a/css/main.scss b/css/main.scss index f22d26ed4..198b29c35 100755 --- a/css/main.scss +++ b/css/main.scss @@ -51,3 +51,4 @@ a:hover .image{opacity:0.2;} .border-1 { border-width: 1px; } .border-1:active { border-width: 1px; } .capitalize { text-transform: capitalize; } +.align-middle { vertical-align: middle; } // imported from basscss 8 diff --git a/js/duration.js b/js/duration.js new file mode 100644 index 000000000..23b0dc108 --- /dev/null +++ b/js/duration.js @@ -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(); +}); From 04fe007b13be5f590fbb3a51aaeab8c4d2a95805 Mon Sep 17 00:00:00 2001 From: Rue Turner Date: Thu, 30 Apr 2020 13:49:33 +0100 Subject: [PATCH 07/10] Tolerate lowercase Allow users to use lowercase in the definitions. This can lead to better readability: preptime: 1h20m --- _includes/timings.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/_includes/timings.html b/_includes/timings.html index 82f7cc50c..419abe89b 100644 --- a/_includes/timings.html +++ b/_includes/timings.html @@ -4,17 +4,17 @@
    Prep - +
    - + {% endif %} {% if thisRecipe.cooktime %}
    Cook - +
    - + {% endif %}

    {% assign thisRecipe = nil %} From 7eabe0ff929c8926c56c3eae2748c34bcda1c05b Mon Sep 17 00:00:00 2001 From: Rue Turner Date: Thu, 30 Apr 2020 15:04:22 +0100 Subject: [PATCH 08/10] cleanup --- .gitignore | 11 ++----- Gemfile | 9 ------ Gemfile.lock | 77 -------------------------------------------- _plugins/Duration.rb | 12 ------- 4 files changed, 2 insertions(+), 107 deletions(-) delete mode 100644 Gemfile delete mode 100644 Gemfile.lock delete mode 100644 _plugins/Duration.rb diff --git a/.gitignore b/.gitignore index 06423a739..5b18b54a8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,3 @@ /.c9 -# Ignore metadata generated by Jekyll -_site/ -.sass-cache/ -.jekyll-cache/ -.jekyll-metadata - -# Ignore folders generated by Bundler -.bundle/ -vendor/ +/_site/ +/.jekyll-cache/ diff --git a/Gemfile b/Gemfile deleted file mode 100644 index 2c5f18b4c..000000000 --- a/Gemfile +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -source "https://rubygems.org" - -git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } - -gem "jekyll", "~> 4.0" - -gem "activesupport" diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 3570ea8c0..000000000 --- a/Gemfile.lock +++ /dev/null @@ -1,77 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - activesupport (6.0.2.1) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - zeitwerk (~> 2.2) - addressable (2.7.0) - public_suffix (>= 2.0.2, < 5.0) - colorator (1.1.0) - concurrent-ruby (1.1.6) - em-websocket (0.5.1) - eventmachine (>= 0.12.9) - http_parser.rb (~> 0.6.0) - eventmachine (1.2.7) - ffi (1.12.2) - forwardable-extended (2.6.0) - http_parser.rb (0.6.0) - i18n (1.8.2) - concurrent-ruby (~> 1.0) - jekyll (4.0.0) - addressable (~> 2.4) - colorator (~> 1.0) - em-websocket (~> 0.5) - i18n (>= 0.9.5, < 2) - jekyll-sass-converter (~> 2.0) - jekyll-watch (~> 2.0) - kramdown (~> 2.1) - kramdown-parser-gfm (~> 1.0) - liquid (~> 4.0) - mercenary (~> 0.3.3) - pathutil (~> 0.9) - rouge (~> 3.0) - safe_yaml (~> 1.0) - terminal-table (~> 1.8) - jekyll-sass-converter (2.1.0) - sassc (> 2.0.1, < 3.0) - jekyll-watch (2.2.1) - listen (~> 3.0) - kramdown (2.1.0) - kramdown-parser-gfm (1.1.0) - kramdown (~> 2.0) - liquid (4.0.3) - listen (3.2.1) - rb-fsevent (~> 0.10, >= 0.10.3) - rb-inotify (~> 0.9, >= 0.9.10) - mercenary (0.3.6) - minitest (5.14.0) - pathutil (0.16.2) - forwardable-extended (~> 2.6) - public_suffix (4.0.3) - rb-fsevent (0.10.3) - rb-inotify (0.10.1) - ffi (~> 1.0) - rouge (3.16.0) - safe_yaml (1.0.5) - sassc (2.2.1) - ffi (~> 1.9) - terminal-table (1.8.0) - unicode-display_width (~> 1.1, >= 1.1.1) - thread_safe (0.3.6) - tzinfo (1.2.6) - thread_safe (~> 0.1) - unicode-display_width (1.6.1) - zeitwerk (2.2.2) - -PLATFORMS - ruby - -DEPENDENCIES - activesupport - jekyll (~> 4.0) - -BUNDLED WITH - 2.1.4 diff --git a/_plugins/Duration.rb b/_plugins/Duration.rb deleted file mode 100644 index a66d9b87a..000000000 --- a/_plugins/Duration.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'active_support' -require 'active_support/duration' - -module Jekyll - module Duration - def humanize_duration(isoduration) - ActiveSupport::Duration.parse(isoduration.upcase).inspect - end - end -end - -Liquid::Template.register_filter(Jekyll::Duration) From 67fb09b8b56ebf495c0b2c3d6e1d602acbff46b4 Mon Sep 17 00:00:00 2001 From: Rue Turner Date: Thu, 30 Apr 2020 15:38:11 +0100 Subject: [PATCH 09/10] unique dom id for timings allows for multiple timings per page like when using components --- _includes/timings.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_includes/timings.html b/_includes/timings.html index 419abe89b..cc4668e8c 100644 --- a/_includes/timings.html +++ b/_includes/timings.html @@ -4,7 +4,7 @@
    Prep - +
    {% endif %} @@ -12,7 +12,7 @@
    Cook - +
    {% endif %} From 31a2974e3af3b7e511f44a3af6399ff893160803 Mon Sep 17 00:00:00 2001 From: Rue Turner Date: Sun, 8 Nov 2020 07:41:43 +0000 Subject: [PATCH 10/10] include schema totalTime --- _includes/timings.html | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/_includes/timings.html b/_includes/timings.html index cc4668e8c..605d6f5df 100644 --- a/_includes/timings.html +++ b/_includes/timings.html @@ -16,5 +16,13 @@
    {% endif %} + {% if thisRecipe.totaltime %} +
    + + Total + +
    + +{% endif %}
    {% assign thisRecipe = nil %}