Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] InspireHEP social and citation count badge #2638

Merged
merged 6 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ Feel free to add your own page(s) by sending a PR.
<a href="https://tonideleo.github.io/" target="_blank">★</a>
<a href="https://alonkellner.com/" target="_blank">★</a>
<a href="http://berylbir.github.io/" target="_blank">★</a>
<a href="http://thefermi0n.github.io/" target="_blank">★</a>
TheFermi0n marked this conversation as resolved.
Show resolved Hide resolved
</td>
</tr>
<tr>
Expand Down
3 changes: 2 additions & 1 deletion _bibliography/papers.bib
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ @article{PhysRev.47.777
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<br>† Albert Einstein},
selected={true}
selected={true},
inspirehep_id = {3255}
}

@article{einstein1905molekularkinetischen,
Expand Down
2 changes: 2 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ publons_id: # your ID on Publons
quora_username: # your Quora username
research_gate_profile: # your profile on ResearchGate
scholar_userid: qc6CJjYAAAAJ # your Google Scholar ID
inspirehep_id: 1010907 # Inspire HEP author ID
TheFermi0n marked this conversation as resolved.
Show resolved Hide resolved
scopus_id: # your profile on Scopus
semanticscholar_id: # your Semantic Scholar ID
spotify_id: # your spotify id
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions _includes/social.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
{% if site.scholar_userid %}
<a href="https://scholar.google.com/citations?user={{ site.scholar_userid }}" title="Google Scholar"><i class="ai ai-google-scholar"></i></a>
{% endif %}
{% if site.inspirehep_id %}
<a href="https://inspirehep.net/authors/{{ site.inspirehep_id }}" title="Inspire HEP"><i class="ai ai-inspire"></i></a>
{% endif %}
{% if site.semanticscholar_id %}
<a href="https://www.semanticscholar.org/author/{{ site.semanticscholar_id }}" title="Semantic Scholar"><i class="ai ai-semantic-scholar"></i></a>
{% endif %}
Expand Down
19 changes: 18 additions & 1 deletion _layouts/bib.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
<div class="badges">
{% if site.enable_publication_badges.altmetric and entry_has_altmetric_badge %}
<span
Expand Down Expand Up @@ -312,6 +317,18 @@
>
</a>
{% endif %}
{% if site.enable_publication_badges.inspirehep and entry_has_inspirehep_badge %}
<a
href="https://inspirehep.net/literature/{{ entry.inspirehep_id }}"
aria-label="Inspirehep link"
role="button"
>
<img
src="https://img.shields.io/badge/inspire-{% inspirehep_citations entry.inspirehep_id %}-001628?logo=inspire&logoColor=001628&labelColor=beige"
alt="{% inspirehep_citations entry.inspirehep_id %} InspireHEP citations"
>
</a>
{% endif %}
</div>
{% endif %}
{% endif %}
Expand Down
57 changes: 57 additions & 0 deletions _plugins/inspirehep-citations.rb
Original file line number Diff line number Diff line change
@@ -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)