-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance the RIS files and use the highwire meta tag conventions for m…
…etadata output
- Loading branch information
Adam Constabaris
authored and
Genia Kazymova
committed
Jan 19, 2024
1 parent
24616b2
commit c532034
Showing
11 changed files
with
169 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.2.15 | ||
2.2.16 |
3 changes: 3 additions & 0 deletions
3
app/components/trln_argon/highwire_metadata_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<% @document.highwire_metadata_tags.each do |name, content| %> | ||
<meta name="<%= name %>" content="<%= content %>"> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module TrlnArgon | ||
class HighwireMetadataComponent < Blacklight::Component | ||
def initialize(document) | ||
super | ||
@document = document | ||
end | ||
|
||
def render? | ||
@document.present? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
module TrlnArgon | ||
module SolrDocument | ||
module HighwireFieldMapping | ||
# https://raw.githubusercontent.com/zotero/translators/db2771d52d89d1480ff98efbd6968565893f2184/Embedded%20Metadata.js | ||
MAPPING = { | ||
'title_main' => 'citation_title', | ||
'publication_year_sort' => 'citation_publication_date', | ||
'publisher_a' => 'citation_publisher', | ||
'publisher_location_a' => 'citation_place', | ||
'isbn_number_a' => 'citation_isbn', | ||
'statement_of_responsibility_a' => 'citation_author', | ||
'issn_primary_a' => 'citation_issn', | ||
'language_a' => 'citation_language' | ||
}.freeze | ||
|
||
def highwire_metadata_tags | ||
result = MAPPING.each_with_object([]) do |(k, v), o| | ||
docvalue = fetch(k, []) | ||
process_docvalue(o, v, docvalue) unless docvalue.empty? | ||
end | ||
|
||
auths = highwire_authors | ||
editors = highwire_editors | ||
process_authors(result, auths) if auths | ||
process_editors(result, editors) if editors | ||
|
||
result | ||
end | ||
|
||
private | ||
|
||
def process_docvalue(result, key, docvalue) | ||
if docvalue.is_a?(Array) | ||
docvalue.each { |dv| result << [key, dv] } | ||
else | ||
result << [key, docvalue] | ||
end | ||
end | ||
|
||
def process_authors(result, auths) | ||
result.reject! { |x| x[0] == 'citation_author' } | ||
auths.each { |n| result << ['citation_authors', n] } | ||
end | ||
|
||
def process_editors(result, editors) | ||
result.reject! { |x| x[0] == 'citation_editor' } | ||
editors.each { |n| result << ['citation_editors', n] } | ||
end | ||
|
||
def highwire_authors | ||
named_authors = names.select { |n| n.fetch(:rel, '') == 'author' } | ||
named_directors = names.select { |n| n.fetch(:rel, '') == 'director' } | ||
named_norel = names.select { |n| n.fetch(:rel, '').empty? } | ||
[named_authors, named_directors, named_norel].flat_map { |x| x.map { |h| h[:name] } } | ||
end | ||
|
||
def highwire_editors | ||
named_editors = names.select { |n| n.fetch(:rel, '') == 'editor' } | ||
[named_editors].find { |x| !x.empty? }&.map { |x| x[:name] } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# rubocop:disable RSpec/FilePath | ||
describe TrlnArgon::SolrDocument::HighwireFieldMapping do | ||
include described_class | ||
# rubocop:disable RSpec/LeakyConstantDeclaration | ||
class SolrDocumentTestClass | ||
include Blacklight::Solr::Document | ||
include TrlnArgon::SolrDocument | ||
end | ||
# rubocop:enable RSpec/LeakyConstantDeclaration | ||
|
||
describe '#highwire_metadata_tags' do | ||
let(:document1) do | ||
SolrDocumentTestClass.new( | ||
'title_main' => 'Title', | ||
'publisher_a' => 'Publisher', | ||
'publication_year_sort' => '2023', | ||
'isbn_number_a' => '12345678', | ||
'publisher_location_a' => 'Durham', | ||
'language_a' => 'English', | ||
'statement_of_responsibility_a' => [ | ||
{ name: 'Author 1', rel: 'author' }, | ||
{ name: 'Author 2', rel: 'editor' } | ||
] | ||
) | ||
end | ||
|
||
let(:document2) do | ||
SolrDocumentTestClass.new( | ||
'title_main' => 'Title', | ||
'publisher_a' => 'Publisher' | ||
) | ||
end | ||
|
||
let(:document3) do | ||
SolrDocumentTestClass.new( | ||
'title_main' => 'Title', | ||
'publisher_a' => 'Publisher', | ||
'issn_primary_a' => '123456' | ||
) | ||
end | ||
|
||
it 'generates metadata tags based on the mapping' do | ||
result = document1.highwire_metadata_tags | ||
expect(result).to include( | ||
['citation_title', 'Title'], | ||
['citation_publication_date', '2023'], | ||
['citation_publisher', 'Publisher'], | ||
['citation_place', 'Durham'], | ||
['citation_isbn', '12345678'], | ||
['citation_language', 'English'], | ||
['citation_author', { 'name' => 'Author 1', 'rel' => 'author' }], | ||
['citation_author', { 'name' => 'Author 2', 'rel' => 'editor' }] | ||
) | ||
end | ||
|
||
it 'does not include citation_author if there are no authors' do | ||
result = document2.highwire_metadata_tags | ||
expect(result).not_to include(['citation_author']) | ||
end | ||
|
||
it 'includes issn if there is an issn' do | ||
result = document3.highwire_metadata_tags | ||
expect(result).to include( | ||
['citation_title', 'Title'], | ||
['citation_publisher', 'Publisher'], | ||
['citation_issn', '123456'] | ||
) | ||
end | ||
end | ||
end | ||
# rubocop:enable RSpec/FilePath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters