Skip to content

Commit dfc7453

Browse files
[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.
1 parent 3ff7579 commit dfc7453

6 files changed

Lines changed: 84 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ Feel free to add your own page(s) by sending a PR.
145145
<a href="https://acad.garywei.dev/" target="_blank">★</a>
146146
<a href="https://tonideleo.github.io/" target="_blank">★</a>
147147
<a href="https://alonkellner.com/" target="_blank">★</a>
148-
<a href="http://berylbir.github.io/" target="_blank">★</a>
148+
<a href="https://berylbir.github.io/" target="_blank">★</a>
149+
<a href="https://thefermi0n.github.io/" target="_blank">★</a>
149150
</td>
150151
</tr>
151152
<tr>

_bibliography/papers.bib

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ @article{PhysRev.47.777
5757
video={https://www.youtube-nocookie.com/embed/aqz-KE-bpKQ},
5858
additional_info={. *More Information* can be [found here](https://github.com/alshedivat/al-folio/)},
5959
annotation={* Example use of superscripts<br>† Albert Einstein},
60-
selected={true}
60+
selected={true},
61+
inspirehep_id = {3255}
6162
}
6263

6364
@article{einstein1905molekularkinetischen,

_config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ flickr_id: # your flickr id
8181
github_username: # your GitHub user name
8282
gitlab_username: # your GitLab user name
8383
ieee_id: # your ieeexplore.ieee.org/author/id
84+
inspirehep_id: 1010907 # Inspire HEP author ID
8485
instagram_id: # your instagram id
8586
kaggle_id: # your kaggle id
8687
keybase_username: # your keybase user name
@@ -342,6 +343,7 @@ enable_publication_badges:
342343
altmetric: true # Altmetric badge (Customization options: https://badge-docs.altmetric.com/index.html)
343344
dimensions: true # Dimensions badge (Customization options: https://badge.dimensions.ai/)
344345
google_scholar: true # Google Scholar badge (https://scholar.google.com/intl/en/scholar/citations.html)
346+
inspirehep: true # Inspire HEP badge (https://help.inspirehep.net/knowledge-base/citation-metrics/)
345347

346348
# Filter out certain bibtex entry keywords used internally from the bib output
347349
filtered_bibtex_keywords:

_includes/social.liquid

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
{% if site.scholar_userid %}
1414
<a href="https://scholar.google.com/citations?user={{ site.scholar_userid }}" title="Google Scholar"><i class="ai ai-google-scholar"></i></a>
1515
{% endif %}
16+
{% if site.inspirehep_id %}
17+
<a href="https://inspirehep.net/authors/{{ site.inspirehep_id }}" title="Inspire HEP"><i class="ai ai-inspire"></i></a>
18+
{% endif %}
1619
{% if site.semanticscholar_id %}
1720
<a href="https://www.semanticscholar.org/author/{{ site.semanticscholar_id }}" title="Semantic Scholar"><i class="ai ai-semantic-scholar"></i></a>
1821
{% endif %}

_layouts/bib.liquid

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,12 @@
263263
{% if entry.google_scholar_id %}
264264
{% assign entry_has_google_scholar_badge = true %}
265265
{% endif %}
266-
{% if entry_has_altmetric_badge or entry_has_dimensions_badge or entry_has_google_scholar_badge %}
266+
267+
{% assign entry_has_inspirehep_badge = false %}
268+
{% if entry.inspirehep_id %}
269+
{% assign entry_has_inspirehep_badge = true %}
270+
{% endif %}
271+
{% if entry_has_altmetric_badge or entry_has_dimensions_badge or entry_has_google_scholar_badge or entry_has_inspirehep_badge %}
267272
<div class="badges">
268273
{% if site.enable_publication_badges.altmetric and entry_has_altmetric_badge %}
269274
<span
@@ -312,6 +317,18 @@
312317
>
313318
</a>
314319
{% endif %}
320+
{% if site.enable_publication_badges.inspirehep and entry_has_inspirehep_badge %}
321+
<a
322+
href="https://inspirehep.net/literature/{{ entry.inspirehep_id }}"
323+
aria-label="Inspirehep link"
324+
role="button"
325+
>
326+
<img
327+
src="https://img.shields.io/badge/inspire-{% inspirehep_citations entry.inspirehep_id %}-001628?logo=inspire&logoColor=001628&labelColor=beige"
328+
alt="{% inspirehep_citations entry.inspirehep_id %} InspireHEP citations"
329+
>
330+
</a>
331+
{% endif %}
315332
</div>
316333
{% endif %}
317334
{% endif %}

_plugins/inspirehep-citations.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
require "active_support/all"
2+
require 'net/http'
3+
require 'json'
4+
require 'uri'
5+
6+
module Helpers
7+
extend ActiveSupport::NumberHelper
8+
end
9+
10+
module Jekyll
11+
class InspireHEPCitationsTag < Liquid::Tag
12+
Citations = { }
13+
14+
def initialize(tag_name, params, tokens)
15+
super
16+
@recid = params.strip
17+
end
18+
19+
def render(context)
20+
recid = context[@recid.strip]
21+
api_url = "https://inspirehep.net/api/literature/?fields=citation_count&q=recid:#{recid}"
22+
23+
begin
24+
# If the citation count has already been fetched, return it
25+
if InspireHEPCitationsTag::Citations[recid]
26+
return InspireHEPCitationsTag::Citations[recid]
27+
end
28+
29+
# Fetch the citation count from the API
30+
uri = URI(api_url)
31+
response = Net::HTTP.get(uri)
32+
data = JSON.parse(response)
33+
34+
# # Log the response for debugging
35+
# puts "API Response: #{data.inspect}"
36+
37+
# Extract citation count from the JSON data
38+
citation_count = data["hits"]["hits"][0]["metadata"]["citation_count"].to_i
39+
40+
# Format the citation count for readability
41+
citation_count = Helpers.number_to_human(citation_count, format: '%n%u', precision: 2, units: { thousand: 'K', million: 'M', billion: 'B' })
42+
43+
rescue Exception => e
44+
# Handle any errors that may occur during fetching
45+
citation_count = "N/A"
46+
47+
# Print the error message including the exception class and message
48+
puts "Error fetching citation count for #{recid}: #{e.class} - #{e.message}"
49+
end
50+
51+
InspireHEPCitationsTag::Citations[recid] = citation_count
52+
return "#{citation_count}"
53+
end
54+
end
55+
end
56+
57+
Liquid::Template.register_tag('inspirehep_citations', Jekyll::InspireHEPCitationsTag)

0 commit comments

Comments
 (0)