Skip to content

Commit

Permalink
added character stats to tag pages. Addresses #18
Browse files Browse the repository at this point in the history
  • Loading branch information
tecknojock committed Nov 4, 2016
1 parent f664d60 commit a38ab86
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
10 changes: 8 additions & 2 deletions .themes/default/source/_layouts/tag_index.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
layout: page
---

<p class="tag-description">{{ page["description"] }}
<br />There are {{ page["count"] }} {{ page["title"]}}.
{% if page["description"] %}<br />{% endif %}
There are {{ page["count"] }} {{ page["title"]}}.
{% if page['implies'].size > 0 then %}
<br />Tag implies:
{% for t in page["implies"] %}
Expand Down Expand Up @@ -31,6 +31,12 @@
{% endfor %}
{% endif %}
</p>
{% if page["tag"].stats.lines > 0 %}
<p class="stats">
{{page["tag"].name}} said a total of <b>{{page["tag"].stats.lines}} line{% if page["tag"].stats.lines > 1 }%}s{%endif%}, {{page["tag"].stats.wordcount}} words, and {{page["tag"].stats.characters}} characters.</b> <br />
{{page["tag"].name}}'s average line consists of<b> {{page["tag"].stats.wordcount | divided_by: page["tag"].stats.lines | round: 2}} words</b> that themselves average <b>{{page["tag"].stats.characters | minus: page["tag"].stats.wordcount | divided_by: page["tag"].stats.wordcount | round: 2}} characters{% if page["tag"].stats.timelines > 0 %}</b> taking about<b> {{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 %}.</b> <br />
</p > {% endif %}


{% for t in page.rp_tags %}
<a href="{{ base }}{{ site.rp_tag_dir }}/{{ t.dir }}" class="rp-tag {{t.classes}}">{{ t.name }}</a>
Expand Down
12 changes: 11 additions & 1 deletion lib/jekyll/rp_logs/rp_tag_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
4 changes: 4 additions & 0 deletions lib/jekyll/rp_logs/rp_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a38ab86

Please sign in to comment.