From a38ab86bbca892c58c56baadf42c85b68d4f6a71 Mon Sep 17 00:00:00 2001 From: tecknojock Date: Fri, 4 Nov 2016 16:36:01 -0400 Subject: [PATCH] added character stats to tag pages. Addresses https://github.com/tecknojock/jekyll-rp_logs/issues/18 --- .themes/default/source/_layouts/tag_index.html | 10 ++++++++-- lib/jekyll/rp_logs/rp_tag_index.rb | 12 +++++++++++- lib/jekyll/rp_logs/rp_tags.rb | 4 ++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.themes/default/source/_layouts/tag_index.html b/.themes/default/source/_layouts/tag_index.html index 4446ecf..b5b926b 100644 --- a/.themes/default/source/_layouts/tag_index.html +++ b/.themes/default/source/_layouts/tag_index.html @@ -1,9 +1,9 @@ --- layout: page --- -

{{ page["description"] }} -
There are {{ page["count"] }} {{ page["title"]}}. +{% if page["description"] %}
{% endif %} +There are {{ page["count"] }} {{ page["title"]}}. {% if page['implies'].size > 0 then %}
Tag implies: {% for t in page["implies"] %} @@ -31,6 +31,12 @@ {% endfor %} {% endif %}

+{% if page["tag"].stats.lines > 0 %} +

+ {{page["tag"].name}} said a total of {{page["tag"].stats.lines}} line{% if page["tag"].stats.lines > 1 }%}s{%endif%}, {{page["tag"].stats.wordcount}} words, and {{page["tag"].stats.characters}} characters.
+ {{page["tag"].name}}'s average line consists of {{page["tag"].stats.wordcount | divided_by: page["tag"].stats.lines | round: 2}} words that themselves average {{page["tag"].stats.characters | minus: page["tag"].stats.wordcount | divided_by: page["tag"].stats.wordcount | round: 2}} characters{% if page["tag"].stats.timelines > 0 %} taking about {{page["tag"].stats.time | divided_by: page["tag"].stats.timelines | divided_by: 60 | round:2}} minutes, {{page["tag"].stats.time | divided_by: page["tag"].stats.timelines | modulo: 60 }} seconds{% endif %}.
+

{% endif %} + {% for t in page.rp_tags %} {{ t.name }} diff --git a/lib/jekyll/rp_logs/rp_tag_index.rb b/lib/jekyll/rp_logs/rp_tag_index.rb index 7766a32..cf0369a 100644 --- a/lib/jekyll/rp_logs/rp_tag_index.rb +++ b/lib/jekyll/rp_logs/rp_tag_index.rb @@ -47,13 +47,23 @@ def generate(site) tags = rps_by_tag(site) tag_list = Hash.new tag_list.merge! (tags) - + page_stats(tag_list) + tags.each_pair do |tag, pages| site.pages << TagIndex.new(site, site.source, File.join(dir, tag.dir), tag, pages,tag_list) end Jekyll.logger.info "#{tags.size} tag pages generated." end + def page_stats(tags) + tags.each_pair{|tag, pages| + tag.clear_stats! + pages.each{|page| + tag.update_stats! page.data["rp_tags"][page.data["rp_tags"].find_index{tag}].stats + } + } + end + # Returns a hash of tags => [pages with tag] private def rps_by_tag(site) tag_ref = Hash.new { |hash, key| hash[key] = Set.new } diff --git a/lib/jekyll/rp_logs/rp_tags.rb b/lib/jekyll/rp_logs/rp_tags.rb index 21e5ac1..238635b 100644 --- a/lib/jekyll/rp_logs/rp_tags.rb +++ b/lib/jekyll/rp_logs/rp_tags.rb @@ -102,6 +102,10 @@ def update_stats!(newstats) end end + def clear_stats! + @stats = nil + end + ## # Compares two tags. Character tags are less than meta tags, and meta # tags are less than general tags. Two tags of the same type are compared