Jekyll Blog Statistics: a Perl Program to Graph Them
The ProblemI like to report stats about my own blog, as you can see here. But how can I compute such stats? A few years ago I wrote a quick and ugly Perl script that allows me to count and generate some
gnuplotfiles. The problem with such script is that it produces gnuplot files, then I have to run
gnuplotto render some PNG images, move the images, edit the markdown page to insert the results and the images.
Long story short: it is too much work for my laziness to keep stats up-to-date!
That’s why I decided to refactor the script in order to let it do most of the work for me.
jekyll-simple-stats is a repository you can find both on my GitHub and GitLab repositories.
The repository consists of a single Perl 5 script,
jekyll_simple_stats.plthat does the following tasks: 1) it scans the
_posts_directory reading all publishing dates and tags from every markdown post; 2) it builds a
gnuplotfile for every year with the amount of posts discriminated by month, then it produces a PNG file; 3) it builds a
gnuplotfile for main tags for each year (e.g., ten main tags) and provides a PNG graph; 3) it builds an html fragment file that can be included in another page using ‘include’ directive.
So what I’ve done so far is:
- prepare a directory to contain all the images generated by the script;
- include the generated html fragment in my statistic page.
My WorkflowToday, when I wish to update the statistics, I simply do the following steps.
The script infers directories and files by an home for the site, specified with the
% perl jekyll_simple_stat.pl -h ~/git/fluca1978.github.io
stats.htmlfragment is generated in the
postsdirectory is based afte the home
~/git/fluca1978.github.ioand the images are placed under the
images/graphsdirectory, also rooted at the home one.
commit changesReally, nothing else. Already has been already prepared.
There is room for improvementsOf course, jekyll-simple-stats being a two-hours project, there is a lot of room for improvements like adding custom flags, improve the graph generation where I’m totally a newbe, and so on.
In the case you would like to help me on this tiny project, feel free to submit an issue or a pull request!
In the meantime, I hope it can be helpful for you too!