From 19d5b3091efb1539cc08f98b2b4001e52b3efd9a Mon Sep 17 00:00:00 2001 From: Helena Rasche Date: Wed, 21 Feb 2024 15:35:55 +0100 Subject: [PATCH 1/3] fix dupe hands on --- _plugins/gtn.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/_plugins/gtn.rb b/_plugins/gtn.rb index 4107a64991951e..2a0a1262ecf78f 100644 --- a/_plugins/gtn.rb +++ b/_plugins/gtn.rb @@ -577,6 +577,8 @@ def get_og_title(site, page, reverse) og_title.push page['title'] end + og_title.gsub!(/Hands-on: Hands-on:/, 'Hands-on:') + Jekyll.logger.debug "Material #{page['layout']} :: #{page['path']} => #{topic_id}/#{material_id} => #{og_title}" if reverse.to_s == 'true' From 3c760717e64379c31222cbacb9c14f900c13966a Mon Sep 17 00:00:00 2001 From: Helena Rasche Date: Wed, 21 Feb 2024 15:40:19 +0100 Subject: [PATCH 2/3] fix blockquote cites --- _plugins/gtn.rb | 6 ++---- assets/js/main.js | 7 ++++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/_plugins/gtn.rb b/_plugins/gtn.rb index 2a0a1262ecf78f..d370c51cde903a 100644 --- a/_plugins/gtn.rb +++ b/_plugins/gtn.rb @@ -577,14 +577,12 @@ def get_og_title(site, page, reverse) og_title.push page['title'] end - og_title.gsub!(/Hands-on: Hands-on:/, 'Hands-on:') - Jekyll.logger.debug "Material #{page['layout']} :: #{page['path']} => #{topic_id}/#{material_id} => #{og_title}" if reverse.to_s == 'true' - og_title.compact.reverse.join(' / ') + og_title.compact.reverse.join(' / ').gsub(/Hands-on: Hands-on:/, 'Hands-on:') else - og_title.compact.join(' / ') + og_title.compact.join(' / ').gsub(/Hands-on: Hands-on:/, 'Hands-on:') end end diff --git a/assets/js/main.js b/assets/js/main.js index ce4108dc561555..bfe5ef670dd74e 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -198,7 +198,8 @@ var clipboardSnippets=new ClipboardJS('[data-clipboard-snippet]',{ // Cited blockquotes document.querySelectorAll("blockquote[cite],blockquote[author]").forEach(bq => { - var url = bq.getAttribute("cite") ? `Source` : ""; - var author = bq.getAttribute("author") ? "— " + bq.getAttribute("author") + " " : ""; - bq.insertAdjacentHTML("beforeend", `
${author}${url}
`) + let bq_cite = bq.getAttribute("cite"); + let bq_url = bq_cite ? `Source` : ""; + let bq_author = bq.getAttribute("author") ? "— " + bq.getAttribute("author") + " " : ""; + bq.insertAdjacentHTML("beforeend", `
${bq_author}${bq_url}
`) }) From 8b47aa94f3703dce85ae27aa14fb368025524ab1 Mon Sep 17 00:00:00 2001 From: Helena Rasche Date: Wed, 21 Feb 2024 16:08:35 +0100 Subject: [PATCH 3/3] only use recent numbers --- _layouts/tutorial_hands_on.html | 2 +- _plugins/gtn.rb | 31 +++++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/_layouts/tutorial_hands_on.html b/_layouts/tutorial_hands_on.html index f3f603070a7c4f..8d5a143d80f1c8 100644 --- a/_layouts/tutorial_hands_on.html +++ b/_layouts/tutorial_hands_on.html @@ -174,7 +174,7 @@

Under Development!

{% assign feedback_count = site | get_feedback_count: own_material_id %} {% if feedback_count > 0 %} -
{% icon rating %} Rating: {{ site | get_rating:own_material_id }} ({{ site | get_feedback_count: own_material_id }} ratings)
+
{% icon rating %} Rating: {{ site | get_rating_recent:own_material_id }} ({{ site | get_feedback_count_recent: own_material_id }} recent ratings, {{ feedback_count }} all time)
{% endif %}
{% icon version %} Revision: {{ page | get_version_number }}
diff --git a/_plugins/gtn.rb b/_plugins/gtn.rb index d370c51cde903a..78172293e42273 100644 --- a/_plugins/gtn.rb +++ b/_plugins/gtn.rb @@ -376,10 +376,10 @@ def get_version_number(page) Gtn::ModificationTimes.obtain_modification_count(page['path']) end - def get_rating_histogram(site, material_id) + def get_rating_histogram(site, material_id, recent: false) return {} if material_id.nil? - feedbacks = get_feedbacks(site, material_id) + feedbacks = recent ? get_recent_feedbacks_time(site, material_id) : get_feedbacks(site, material_id) return {} if feedbacks.nil? || feedbacks.empty? @@ -398,12 +398,17 @@ def get_rating_histogram_chart(site, material_id) .to_h end - def get_rating(site, material_id) - f = get_rating_histogram(site, material_id) + def get_rating(site, material_id, recent: false) + f = get_rating_histogram(site, material_id, recent: recent) rating = f.map { |k, v| k * v }.sum / f.map { |_k, v| v }.sum.to_f rating.round(1) end + def get_rating_recent(site, material_id) + r = get_rating(site, material_id, recent: true) + r.nan? ? get_rating(site, material_id, recent: false) : r + end + # Only accepts an integer rating def to_stars(rating) if rating.nil? || (rating.to_i < 1) || (rating == '0') || rating.zero? @@ -453,6 +458,24 @@ def get_feedback_count(site, material_id) get_feedbacks(site, material_id).length end + def get_feedback_count_recent(site, material_id) + get_recent_feedbacks_time(site, material_id).length + end + + def get_recent_feedbacks_time(site, material_id) + feedbacks = get_feedbacks(site, material_id) + .select do |f| + f['pro']&.length&.positive? || + f['con']&.length&.positive? + end + .map do |f| + f['f_date'] = Date.parse(f['date']).strftime('%B %Y') + f + end + + feedbacks.select { |f| Date.parse(f['date']) > Date.today - 365 } + end + def get_recent_feedbacks(site, material_id) feedbacks = get_feedbacks(site, material_id) .select do |f|