Skip to content

Commit

Permalink
Add tests and clean up document alternate ignores
Browse files Browse the repository at this point in the history
This also backports #355.

Conflicts:
	src/plugin/document.coffee
  • Loading branch information
tilgovi committed Apr 7, 2014
1 parent 99ee192 commit 18da618
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/plugin/document.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,17 @@ class Annotator.Plugin.Document extends Annotator.Plugin
href = this._absoluteUrl(l.prop('href')) # get absolute url
rel = l.prop('rel')
type = l.prop('type')
if rel in ["alternate", "canonical", "bookmark"] and type not in ["application/rss+xml", "application/atom+xml"]
@metadata.link.push(href: href, rel: rel, type: type)
lang = l.prop('hreflang')

if rel not in ["alternate", "canonical", "bookmark"] then continue

if rel is 'alternate'
# Ignore feeds resources
if type and type.match /^application\/(rss|atom)\+xml/ then continue
# Ignore alternate languages
if lang then continue

@metadata.link.push(href: href, rel: rel, type: type)

# look for links in scholar metadata
for name, values of @metadata.highwire
Expand Down
5 changes: 5 additions & 0 deletions test/spec/plugin/document_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe 'Annotator.Plugin.Document', ->
head.append('<link rel="alternate" href="foo.pdf" type="application/pdf"></link>')
head.append('<link rel="alternate" href="foo.doc" type="application/msword"></link>')
head.append('<link rel="bookmark" href="http://example.com/bookmark"></link>')
head.append('<link rel="alternate" href="es/foo.html" hreflang="es" type="text/html"></link>')
head.append('<meta name="citation_doi" content="10.1175/JCLI-D-11-00015.1">')
head.append('<meta name="citation_title" content="Foo">')
head.append('<meta name="citation_pdf_url" content="foo.pdf">')
Expand All @@ -33,6 +34,7 @@ describe 'Annotator.Plugin.Document', ->
head.append('<link rel="icon" href="http://example.com/images/icon.ico"></link>')
head.append('<meta name="eprints.title" content="Computer Lib / Dream Machines">')
head.append('<meta name="prism.title" content="Literary Machines">')
head.append('<link rel="alternate" href="feed" type="application/rss+xml"></link>')

annotation = null

Expand Down Expand Up @@ -65,6 +67,9 @@ describe 'Annotator.Plugin.Document', ->
assert.equal(annotation.document.link[5].type, "application/pdf")
assert.equal(annotation.document.link[6].href, "doi:10.1175/JCLI-D-11-00015.1")

it 'should ignore atom and RSS feeds and alternate languages', ->
assert.equal(annotation.document.link.length, 7)

it 'should have highwire metadata', ->
assert.ok(annotation.document.highwire)
assert.deepEqual(annotation.document.highwire.pdf_url, ['foo.pdf'])
Expand Down

0 comments on commit 18da618

Please sign in to comment.