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 4107a64991951e..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| @@ -580,9 +603,9 @@ def get_og_title(site, page, reverse) 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", ``) + let bq_cite = bq.getAttribute("cite"); + let bq_url = bq_cite ? `Source` : ""; + let bq_author = bq.getAttribute("author") ? "— " + bq.getAttribute("author") + " " : ""; + bq.insertAdjacentHTML("beforeend", ``) })