Commit 12caee84 authored by Robert Knight's avatar Robert Knight Committed by GitHub

Merge pull request #500 from evidentpoint/doc-equivalence

Use a URN derived from DC meta tags for creating equivalent doc links
parents 9a46f055 82ac90d0
...@@ -159,6 +159,21 @@ module.exports = class Document extends Plugin ...@@ -159,6 +159,21 @@ module.exports = class Document extends Plugin
if id[0..3] == "doi:" if id[0..3] == "doi:"
@metadata.link.push(href: id) @metadata.link.push(href: id)
# look for a link to identify the resource in dublincore metadata
dcRelationValues = @metadata.dc['relation.ispartof']
dcIdentifierValues = @metadata.dc['identifier']
if dcRelationValues && dcIdentifierValues
dcUrnRelationComponent =
dcRelationValues[dcRelationValues.length - 1]
dcUrnIdentifierComponent =
dcIdentifierValues[dcIdentifierValues.length - 1]
dcUrn = 'urn:x-dc:' +
encodeURIComponent(dcUrnRelationComponent) + '/' +
encodeURIComponent(dcUrnIdentifierComponent)
@metadata.link.push(href: dcUrn)
# set this as the documentFingerprint as a hint to include this in search queries
@metadata.documentFingerprint = dcUrn
_getFavicon: => _getFavicon: =>
for link in $("link") for link in $("link")
if $(link).prop("rel") in ["shortcut icon", "icon"] if $(link).prop("rel") in ["shortcut icon", "icon"]
...@@ -180,4 +195,4 @@ module.exports = class Document extends Plugin ...@@ -180,4 +195,4 @@ module.exports = class Document extends Plugin
if new URL(href).protocol != new URL(baseURI).protocol if new URL(href).protocol != new URL(baseURI).protocol
# use the baseURI instead since it's likely what's intended # use the baseURI instead since it's likely what's intended
href = baseURI href = baseURI
return href return href
\ No newline at end of file
...@@ -41,7 +41,8 @@ describe 'Document', -> ...@@ -41,7 +41,8 @@ describe 'Document', ->
head.append('<meta name="citation_title" content="Foo">') head.append('<meta name="citation_title" content="Foo">')
head.append('<meta name="citation_pdf_url" content="foo.pdf">') head.append('<meta name="citation_pdf_url" content="foo.pdf">')
head.append('<meta name="dc.identifier" content="doi:10.1175/JCLI-D-11-00015.1">') head.append('<meta name="dc.identifier" content="doi:10.1175/JCLI-D-11-00015.1">')
head.append('<meta name="dc:identifier" content="isbn:123456789">') head.append('<meta name="dc:identifier" content="foobar-abcxyz">')
head.append('<meta name="dc.relation.ispartof" content="isbn:123456789">')
head.append('<meta name="DC.type" content="Article">') head.append('<meta name="DC.type" content="Article">')
head.append('<meta property="og:url" content="http://example.com">') head.append('<meta property="og:url" content="http://example.com">')
head.append('<meta name="twitter:site" content="@okfn">') head.append('<meta name="twitter:site" content="@okfn">')
...@@ -65,7 +66,7 @@ describe 'Document', -> ...@@ -65,7 +66,7 @@ describe 'Document', ->
it 'should have links with absolute hrefs and types', -> it 'should have links with absolute hrefs and types', ->
assert.ok(metadata.link) assert.ok(metadata.link)
assert.equal(metadata.link.length, 9) assert.equal(metadata.link.length, 10)
assert.match(metadata.link[0].href, docBaseUri) assert.match(metadata.link[0].href, docBaseUri)
assert.equal(metadata.link[1].rel, "alternate") assert.equal(metadata.link[1].rel, "alternate")
assert.match(metadata.link[1].href, /^.+foo\.pdf$/) assert.match(metadata.link[1].href, /^.+foo\.pdf$/)
...@@ -84,8 +85,16 @@ describe 'Document', -> ...@@ -84,8 +85,16 @@ describe 'Document', ->
assert.equal(metadata.link[7].type, "application/pdf") assert.equal(metadata.link[7].type, "application/pdf")
assert.equal(metadata.link[8].href, "doi:10.1175/JCLI-D-11-00015.1") assert.equal(metadata.link[8].href, "doi:10.1175/JCLI-D-11-00015.1")
# Link derived from dc resource identifiers in the form of urn:x-dc:<container>/<identifier>
# Where <container> is the percent-encoded value of the last dc.relation.ispartof meta element
# and <identifier> is the percent-encoded value of the last dc.identifier meta element.
assert.equal(
metadata.link[9].href
"urn:x-dc:isbn%3A123456789/foobar-abcxyz"
)
it 'should ignore atom and RSS feeds and alternate languages', -> it 'should ignore atom and RSS feeds and alternate languages', ->
assert.equal(metadata.link.length, 9) assert.equal(metadata.link.length, 10)
it 'should have highwire metadata', -> it 'should have highwire metadata', ->
assert.ok(metadata.highwire) assert.ok(metadata.highwire)
...@@ -95,7 +104,8 @@ describe 'Document', -> ...@@ -95,7 +104,8 @@ describe 'Document', ->
it 'should have dublincore metadata', -> it 'should have dublincore metadata', ->
assert.ok(metadata.dc) assert.ok(metadata.dc)
assert.deepEqual(metadata.dc.identifier, ["doi:10.1175/JCLI-D-11-00015.1", "isbn:123456789"]) assert.deepEqual(metadata.dc.identifier, ["doi:10.1175/JCLI-D-11-00015.1", "foobar-abcxyz"])
assert.deepEqual(metadata.dc['relation.ispartof'], ["isbn:123456789"])
assert.deepEqual(metadata.dc.type, ["Article"]) assert.deepEqual(metadata.dc.type, ["Article"])
it 'should have facebook metadata', -> it 'should have facebook metadata', ->
...@@ -116,7 +126,7 @@ describe 'Document', -> ...@@ -116,7 +126,7 @@ describe 'Document', ->
it 'should have unique uris', -> it 'should have unique uris', ->
uris = testDocument.uris() uris = testDocument.uris()
assert.equal(uris.length, 7) assert.equal(uris.length, 8)
it 'uri() returns the canonical uri', -> it 'uri() returns the canonical uri', ->
uri = testDocument.uri() uri = testDocument.uri()
...@@ -128,6 +138,10 @@ describe 'Document', -> ...@@ -128,6 +138,10 @@ describe 'Document', ->
'http://example.com/images/icon.ico' 'http://example.com/images/icon.ico'
) )
it 'should have a documentFingerprint as the dc resource identifiers URN href', ->
assert.equal(metadata.documentFingerprint, metadata.link[9].href)
describe '#_absoluteUrl', -> describe '#_absoluteUrl', ->
it 'should add the protocol when the url starts with two slashes', -> it 'should add the protocol when the url starts with two slashes', ->
...@@ -168,4 +182,4 @@ describe 'Document', -> ...@@ -168,4 +182,4 @@ describe 'Document', ->
'document-base-uri': document.location.href 'document-base-uri': document.location.href
}) })
altDocument = new Document($('<div></div>')[0], {}) altDocument = new Document($('<div></div>')[0], {})
assert.equal(altDocument._getDocumentHref(), document.location.href) assert.equal(altDocument._getDocumentHref(), document.location.href)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment