From dfc7453ea08fd51f4598685b16130a13e69fe05e Mon Sep 17 00:00:00 2001 From: Riasat Sheikh Date: Mon, 19 Aug 2024 12:03:01 +0900 Subject: [PATCH] [Feature] InspireHEP social and citation count badge (#2638) [INSPIRE](http://inspirehep.net/) is a trusted community hub that facilitates the sharing and discovery of accurate scholarly information in high energy physics. By integrating the social and citation count badge, al-folio users within this community will gain significant benefits. In continuation of #2634, I am creating this pull request. ## Details ### Social Icon - Add your INSPIRE author ID in the `config.yml` under `inspirehep_id`. ### Citation Count - Enable this feature by setting `inspirehep` to `true` under `enable_publication_badges` in your `config.yml` file. - In your bibliography file (e.g., `papers.bib`), add `inspirehep_id = {the literature's recid}` under the citation of a literature source. --- README.md | 3 +- _bibliography/papers.bib | 3 +- _config.yml | 2 ++ _includes/social.liquid | 3 ++ _layouts/bib.liquid | 19 ++++++++++- _plugins/inspirehep-citations.rb | 57 ++++++++++++++++++++++++++++++++ 6 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 _plugins/inspirehep-citations.rb diff --git a/README.md b/README.md index c64b3fd..b9a72a8 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,8 @@ Feel free to add your own page(s) by sending a PR. - + + diff --git a/_bibliography/papers.bib b/_bibliography/papers.bib index bf532eb..d8c6b05 100644 --- a/_bibliography/papers.bib +++ b/_bibliography/papers.bib @@ -57,7 +57,8 @@ video={https://www.youtube-nocookie.com/embed/aqz-KE-bpKQ}, additional_info={. *More Information* can be [found here](https://github.com/alshedivat/al-folio/)}, annotation={* Example use of superscripts
† Albert Einstein}, - selected={true} + selected={true}, + inspirehep_id = {3255} } @article{einstein1905molekularkinetischen, diff --git a/_config.yml b/_config.yml index 134bb28..b3c5d0f 100644 --- a/_config.yml +++ b/_config.yml @@ -81,6 +81,7 @@ flickr_id: # your flickr id github_username: # your GitHub user name gitlab_username: # your GitLab user name ieee_id: # your ieeexplore.ieee.org/author/id +inspirehep_id: 1010907 # Inspire HEP author ID instagram_id: # your instagram id kaggle_id: # your kaggle id keybase_username: # your keybase user name @@ -342,6 +343,7 @@ enable_publication_badges: altmetric: true # Altmetric badge (Customization options: https://badge-docs.altmetric.com/index.html) dimensions: true # Dimensions badge (Customization options: https://badge.dimensions.ai/) google_scholar: true # Google Scholar badge (https://scholar.google.com/intl/en/scholar/citations.html) + inspirehep: true # Inspire HEP badge (https://help.inspirehep.net/knowledge-base/citation-metrics/) # Filter out certain bibtex entry keywords used internally from the bib output filtered_bibtex_keywords: diff --git a/_includes/social.liquid b/_includes/social.liquid index 0e4f395..22d4f79 100644 --- a/_includes/social.liquid +++ b/_includes/social.liquid @@ -13,6 +13,9 @@ {% if site.scholar_userid %} {% endif %} +{% if site.inspirehep_id %} + +{% endif %} {% if site.semanticscholar_id %} {% endif %} diff --git a/_layouts/bib.liquid b/_layouts/bib.liquid index 782d48c..3a1b6f1 100644 --- a/_layouts/bib.liquid +++ b/_layouts/bib.liquid @@ -263,7 +263,12 @@ {% if entry.google_scholar_id %} {% assign entry_has_google_scholar_badge = true %} {% endif %} - {% if entry_has_altmetric_badge or entry_has_dimensions_badge or entry_has_google_scholar_badge %} + + {% assign entry_has_inspirehep_badge = false %} + {% if entry.inspirehep_id %} + {% assign entry_has_inspirehep_badge = true %} + {% endif %} + {% if entry_has_altmetric_badge or entry_has_dimensions_badge or entry_has_google_scholar_badge or entry_has_inspirehep_badge %}
{% if site.enable_publication_badges.altmetric and entry_has_altmetric_badge %} {% endif %} + {% if site.enable_publication_badges.inspirehep and entry_has_inspirehep_badge %} + + {% inspirehep_citations entry.inspirehep_id %} InspireHEP citations + + {% endif %}
{% endif %} {% endif %} diff --git a/_plugins/inspirehep-citations.rb b/_plugins/inspirehep-citations.rb new file mode 100644 index 0000000..63f5927 --- /dev/null +++ b/_plugins/inspirehep-citations.rb @@ -0,0 +1,57 @@ +require "active_support/all" +require 'net/http' +require 'json' +require 'uri' + +module Helpers + extend ActiveSupport::NumberHelper +end + +module Jekyll + class InspireHEPCitationsTag < Liquid::Tag + Citations = { } + + def initialize(tag_name, params, tokens) + super + @recid = params.strip + end + + def render(context) + recid = context[@recid.strip] + api_url = "https://inspirehep.net/api/literature/?fields=citation_count&q=recid:#{recid}" + + begin + # If the citation count has already been fetched, return it + if InspireHEPCitationsTag::Citations[recid] + return InspireHEPCitationsTag::Citations[recid] + end + + # Fetch the citation count from the API + uri = URI(api_url) + response = Net::HTTP.get(uri) + data = JSON.parse(response) + + # # Log the response for debugging + # puts "API Response: #{data.inspect}" + + # Extract citation count from the JSON data + citation_count = data["hits"]["hits"][0]["metadata"]["citation_count"].to_i + + # Format the citation count for readability + citation_count = Helpers.number_to_human(citation_count, format: '%n%u', precision: 2, units: { thousand: 'K', million: 'M', billion: 'B' }) + + rescue Exception => e + # Handle any errors that may occur during fetching + citation_count = "N/A" + + # Print the error message including the exception class and message + puts "Error fetching citation count for #{recid}: #{e.class} - #{e.message}" + end + + InspireHEPCitationsTag::Citations[recid] = citation_count + return "#{citation_count}" + end + end +end + +Liquid::Template.register_tag('inspirehep_citations', Jekyll::InspireHEPCitationsTag)