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

Adds almetric badge #729

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions app/assets/stylesheets/application.sass.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@
.record-metadata {
margin-bottom: 2em;
}

.altmetric-embed a {
border-bottom: none;
}
11 changes: 11 additions & 0 deletions app/views/purl/_stats.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% if document.doi.present? %>
<div class="section">
<div class="section-heading">
<h2>Usage metrics</h2>
</div>
<div class="section-body mt-3">
<p><a href="https://help.altmetric.com/support/solutions/articles/6000232837-what-is-altmetric-and-what-does-it-provide-" target='_blank' rel='noopener'>Altmetric</a> tracks online attention to this work. A badge is shown only when online mentions are found.</p>
<div class='altmetric-embed' data-badge-type='donut' data-doi="<%= document.doi_id %>" data-badge-popover='right' data-hide-no-mentions='true'></div>
</div>
</div>
<% end %>
8 changes: 7 additions & 1 deletion app/views/purl/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
<%= tag :link, rel: "alternate", title: "MODS XML", type: 'application/xml', href: purl_url(@purl, format: 'mods') if @purl.mods? %>
<%= tag :link, rel: "alternate", title: "IIIF Manifest", type: 'application/json', href: iiif_manifest_url(@purl) if @purl.iiif_manifest? %>
<%= tag :link, rel: "up", href: purl_url(@purl.containing_collections.first) if @purl.containing_collections.present? %>
<%= tag :meta, name: 'citation_doi', content: @purl.doi_id if @purl.doi.present? %>
<%= tag :meta, name: 'citation_title', content: @purl.title %>
<%= tag :meta, name: 'robots', content: 'noindex' unless @purl.rights.world_downloadable? %>

<% if @purl.doi %>
<script type='text/javascript' src='https://d1bxh8uas1mnw7.cloudfront.net/assets/embed.js'></script>
<%= tag :meta, name: 'citation_doi', content: @purl.doi_id %>
<% end %>
<% end %>

<% keywords(@purl.mods.subject.compact.map(&:values).join(',')) if @purl.mods? && @purl.mods.subject %>
Expand Down Expand Up @@ -50,5 +54,7 @@ end
<% if @purl.mods? %>
<%= render 'mods_metadata_sections', document: @purl %>
<% end %>

<%= render 'stats', document: @purl %>
</div>
</div>
5 changes: 4 additions & 1 deletion spec/features/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,13 @@
end

context 'item with a DOI' do
it 'includes citation_doi meta tag' do
it 'includes altmetrics' do
visit '/bb051dp0564'

expect(page).to have_selector 'meta[name="citation_doi"][content="10.25740/bb051dp0564"]', visible: :hidden
expect(page).to have_selector 'meta[name="citation_title"][content="The Distinct Impacts of Content Moderation"]', visible: :hidden
expect(page).to have_selector 'script[src="https://d1bxh8uas1mnw7.cloudfront.net/assets/embed.js"]', visible: :hidden
expect(page).to have_css '.altmetric-embed'
end
end

Expand Down