Not to long ago I wrote about how you can change reality by measuring it. Keeping that in mind, I wanted to know more about my publishing statistics, with respect to this blog - I wanted to measure them, and see how far along I’ve come, and how I can improve on publishing, and writing habits. This gave me an idea to write a plugin for Jekyll which did exactly that, because this blog is statically generated with Jekyll.
This further lead to releasing another WordPress plugin, which too does exactly that.
Both are small, and show some useful metadata about your publishing statistics.
For now, the metadata generated, and displayed is:
- Combined, approximate count of words written In all posts.
- Days since the start of your jekyll blog, or your first WordPress post.
- Approximate count of posts published on your blog, so far.
- ~ Average words written/published per day for your jekyll, or WordPress based blog.
I lovingly call it the Statistical Plugin (not very creative, I know).
The Jekyll Plugin
Jekyll’s plugin system is great. I went the custom liquid tag way. To use the plugin to display the metadata, I simply use the custom liquid tag {% content_statistics %}
Note, that it may add to the time it takes for Jekyll to generate your static pages. Not by much, I can vouch for that. But it does add to it.
The Statistics Plugin Code For Jekyll
I am using this plugin / code for displaying the statistical metadata in the footer of this blog.
Here’s how that looks:
Some nice statistical meta data about my publishing habits with respect to this blog.
Here’s the code for the plugin:
require 'date' #needed to do date stuff
module Jekyll
class RenderTotalWords < Liquid::Tag
def render(context)
#reg-ex to strip html
re = /<("[^"]*"|'[^']*'|[^'">])*>/
#init vars
no_of_words = 0
no_of_days_writing = 0
no_of_posts = 0
no_of_words_per_day_written = 0
#NOTE: change the value of the parameter date for date_start to the date you actually started. Look up the date you first published your very first post, if that helps. I remember starting to write, and publish daily since the start of this year. Hence 1-1-2015.
date_start = Date.new(2015,1,1)
date_end = DateTime.now
#calculate the number of days since the blog has started based on date_start and date_end
no_of_days_writing = date_end - date_start
no_of_days_writing = no_of_days_writing.to_i
#fetch all the posts from the site object, using context.registers since we're essentially creating a custom tag
posts = context.registers[:site].posts
#calculate the approximate number of words written in the entire blog. Using posts, and not pages.
posts.each do |post|
stripped_post = post.content.gsub(re,''); #strip html tags using re above.
no_of_words += stripped_post.gsub(/[^-a-zA-Z]/, ' ').split.size #calculate, and add the number of words.
no_of_posts += 1 #calculate the total no of posts, all posts.
end
#calculate the approximate, average no of words written, and published on this blog, per day.
no_of_words_per_day_written = (no_of_words / no_of_posts).to_i
##print it out as a string - feel free to customise this to your hearts content.
"<strong>~#{no_of_words}</strong> Words Written In All Posts. <br><br> <strong>~#{no_of_days_writing}</strong> Days Since The Start Of This Blog. <br><br> <strong>~#{no_of_posts}</strong> Posts Published Here, So Far. <br><br> <strong>~#{no_of_words_per_day_written}</strong> Avg Words Written Per Day For This Blog. "
end
end #class ends here
end #module ends here
#register the custom template tag.
Liquid::Template.register_tag('content_statistics', Jekyll::RenderTotalWords)
The code is really simple, and can be made better. But works just as fine.
Copy, paste, and edit this code. Save it to .rb
file, and drop that in the _plugins
folder. After that just use the {% content_statistics %}
template tag to display all that metadata.
REMINDER: Remember to change / edit the parameter date value for Date.new
to init the start_date
based on the actual starting/publishing date for your blog - manually do this for this plugin to correctly work.
Download The Jekyll Statistical Plugin From GitHub
The WordPress Plugin.
As I mention, I thought it did be nice if something like this was available for WordPress users too. The plugin has been submitted for a review, to be hosted by WordPress.org soon.
Here’s how it looks on a WordPress blog, when using the 2015 theme:
Statistical WordPress Widget: This the how the widget looks in WordPress.
Statistical WordPress Widget: This the how the widget looks in WordPress.
Download The WordPress Statistical Plugin.
Get The Statistics Plugin For Your Blog
Shows useful, statistical information about the content on your blog, in a widget. Metadata displayed: Combined wordcount of all your published posts, Total no of published posts, Avg no of words written per post, and Days since the first post was published. Please note that all counts shown are approximations, based on some simple calculations.