Commit 7b9cbbb7 authored by Juan Corona's avatar Juan Corona Committed by Juan Corona

Use a URN derived from DublinCore meta tags for creating equivalent links...

Use a URN derived from DublinCore meta tags for creating equivalent links across documents that provide ‘dc:source’ and ‘dc:identifier’ tags

This link is now the documentIdentifier for non-PDF cases for the document metadata. This metadata is shared with the sidebar, making this link appear in the list of links for the Search API calls
parent 9a46f055
......@@ -159,6 +159,22 @@ module.exports = class Document extends Plugin
if id[0..3] == "doi:"
@metadata.link.push(href: id)
# look for a link to identify the resource in dublincore data
dcMetaConcat = []
# sort by name for a consistent ordering of the concatenated metadata
for name in Object.keys(@metadata.dc).sort()
# right now only look for these two terms
if name == 'source' || name == 'identifier'
values = @metadata.dc[name].sort().map (v) -> encodeURIComponent(v)
dcMetaConcat.push(name + ':' + values.join(','))
dcMetaUrn = 'urn:x-dc-meta:' + dcMetaConcat.join('/')
if dcMetaConcat.length == 2
# only do this if both terms are provided, for now
@metadata.link.push(href: dcMetaUrn)
# set this as the documentFingerprint as a hint to include this in search queries
@metadata.documentFingerprint = dcMetaUrn
_getFavicon: =>
for link in $("link")
if $(link).prop("rel") in ["shortcut icon", "icon"]
......@@ -180,4 +196,4 @@ module.exports = class Document extends Plugin
if new URL(href).protocol != new URL(baseURI).protocol
# use the baseURI instead since it's likely what's intended
href = baseURI
return href
\ No newline at end of file
return href
......@@ -42,6 +42,7 @@ describe 'Document', ->
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="isbn:123456789">')
head.append('<meta name="dc:source" content="urn:example:abcxyz">')
head.append('<meta name="DC.type" content="Article">')
head.append('<meta property="og:url" content="http://example.com">')
head.append('<meta name="twitter:site" content="@okfn">')
......@@ -65,7 +66,7 @@ describe 'Document', ->
it 'should have links with absolute hrefs and types', ->
assert.ok(metadata.link)
assert.equal(metadata.link.length, 9)
assert.equal(metadata.link.length, 10)
assert.match(metadata.link[0].href, docBaseUri)
assert.equal(metadata.link[1].rel, "alternate")
assert.match(metadata.link[1].href, /^.+foo\.pdf$/)
......@@ -84,8 +85,16 @@ describe 'Document', ->
assert.equal(metadata.link[7].type, "application/pdf")
assert.equal(metadata.link[8].href, "doi:10.1175/JCLI-D-11-00015.1")
# link derived from dc resource identifiers
# should be in the form of `urn:x-dc-meta: identifier: <doi>,<isbn> / source: <example>`
# it's a comma separated list for when there's multiple identifiers
assert.equal(
metadata.link[9].href
"urn:x-dc-meta:identifier:doi%3A10.1175%2FJCLI-D-11-00015.1,isbn%3A123456789/source:urn%3Aexample%3Aabcxyz"
)
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', ->
assert.ok(metadata.highwire)
......@@ -96,6 +105,7 @@ describe 'Document', ->
it 'should have dublincore metadata', ->
assert.ok(metadata.dc)
assert.deepEqual(metadata.dc.identifier, ["doi:10.1175/JCLI-D-11-00015.1", "isbn:123456789"])
assert.deepEqual(metadata.dc.source, ["urn:example:abcxyz"])
assert.deepEqual(metadata.dc.type, ["Article"])
it 'should have facebook metadata', ->
......@@ -116,7 +126,7 @@ describe 'Document', ->
it 'should have unique uris', ->
uris = testDocument.uris()
assert.equal(uris.length, 7)
assert.equal(uris.length, 8)
it 'uri() returns the canonical uri', ->
uri = testDocument.uri()
......@@ -128,6 +138,10 @@ describe 'Document', ->
'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', ->
it 'should add the protocol when the url starts with two slashes', ->
......@@ -168,4 +182,4 @@ describe 'Document', ->
'document-base-uri': document.location.href
})
altDocument = new Document($('<div></div>')[0], {})
assert.equal(altDocument._getDocumentHref(), document.location.href)
\ No newline at end of file
assert.equal(altDocument._getDocumentHref(), document.location.href)
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