From 18da618e876452e7d53374dfa03a765246951bcf Mon Sep 17 00:00:00 2001 From: Randall Leeds Date: Mon, 7 Apr 2014 16:33:43 -0700 Subject: [PATCH] Add tests and clean up document alternate ignores This also backports #355. Conflicts: src/plugin/document.coffee --- src/plugin/document.coffee | 13 +++++++++++-- test/spec/plugin/document_spec.coffee | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/plugin/document.coffee b/src/plugin/document.coffee index e7a7dbe70..299e43541 100644 --- a/src/plugin/document.coffee +++ b/src/plugin/document.coffee @@ -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 diff --git a/test/spec/plugin/document_spec.coffee b/test/spec/plugin/document_spec.coffee index 2bc9ec5db..5dc4310de 100644 --- a/test/spec/plugin/document_spec.coffee +++ b/test/spec/plugin/document_spec.coffee @@ -22,6 +22,7 @@ describe 'Annotator.Plugin.Document', -> head.append('') head.append('') head.append('') + head.append('') head.append('') head.append('') head.append('') @@ -33,6 +34,7 @@ describe 'Annotator.Plugin.Document', -> head.append('') head.append('') head.append('') + head.append('') annotation = null @@ -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'])