Skip to main content

Easily showcase your Google Scholar metrics in Jekyll

Whether you’re applying for academic positions, comparing yourself to your colleagues, or determining whether people on Twitter really deserve their grant funding, it’s important to look at scholarly metrics such as h-index, i10-index, and number of citations. However, showing them off directly in your CV is a major bummer, especially when you’re an academic superstar and are too busy to update these vital statistics for all the conferences, grants, and positions you’re applying for! In this blog post, I’ll tell you three easy steps to automatically fetch these stats from Google Scholar and display them on your online vita with Jekyll.

First, take the below code, save it as a new file, scholar_stats.rb, and place it in your _plugins folder.1

require 'open-uri'
require 'nokogiri'

module Jekyll
  class ScholarStats < Generator
    # Replace `SCHOLAR_ID` with your own Google Scholar ID
    SCHOLAR_ID = 'XXXXXXXXXX'.freeze
    SCHOLAR_URL = 'http://scholar.google.com/citations?hl=en&user='.freeze
    def generate(site)
      doc = Nokogiri::HTML(URI.parse(SCHOLAR_URL + SCHOLAR_ID).open)
      tbl = doc.css('table').first
      tbl_data = { 'id' => SCHOLAR_ID }
      tbl.css('tr')[1..].each do |tr|
        cell_data = tr.css('td').map(&:text)
        tbl_data[cell_data[0].downcase.sub('-', '_')] = cell_data[1].to_i
      end
      site.data['scholar'] = tbl_data
    end
  end
end

Second, update the SCHOLAR_ID constant with your Google Scholar ID. This is taken from the link for your Google Scholar profile, like https://scholar.google.com/citations?user=z5el-twAAAAJ, and it’s the characters after the user= part. The SCHOLAR_ID for this Scholar profile would therefore be z5el-twAAAAJ.

Finally, you might need to add these to your Gemfile and run bundle install:

gem "nokogiri"
gem "open-uri"

Or install them yourself with gem install open-uri nokogiri.

Once you’ve done this, you should have access to a few new variables in your Jekyll installation. You can use them in the Markdown or HTML documents using Liquid templates like so:

* [Profile](https://scholar.google.com/citations?user={{ site.data.scholar.id }})
* Citations: {{ site.data.scholar.citations }}
* h-index: {{ site.data.scholar.h_index }}
* i10-index: {{ site.data.scholar.i10_index }}

This Markdown code on my Jekyll site translates to:

Now sit back, relax, and watch as your numbers go up!

  1. If you are using something like GitHub Pages to publish your site, you might not be able to use custom plugins! Instead, generate your Jekyll site locally and then push the generated static files up to your git repository.

If you found this post useful, please consider supporting my work with a street taco 🌮.