Comparing version 3.1.0 to 3.2.0-master-3043577819-9ca4db98
@@ -7,2 +7,8 @@ # Changelog | ||
## [3.2.0] - 2022-09-17 | ||
### New features | ||
- Articles on Open Journal Systems that do not expose a DOI in the metadata can now still be recognised, as long as the document body is passed as well. | ||
## [3.1.0] - 2019-12-09 | ||
@@ -9,0 +15,0 @@ |
@@ -34,2 +34,12 @@ "use strict"; | ||
var identifiers = metaTagsWithIdentifier.map(function (tag) { return tag.getAttribute('content'); }).filter(isNotNull); | ||
// Open Journal Systems does not necessarily list the DOI in the <head>, | ||
// but if `domTree` includes the <body>, we can at least try to find the link | ||
// there: | ||
var ojsDoiLink = domTree.querySelector('.pkp_structure_main .doi .value a'); | ||
if (ojsDoiLink) { | ||
var ojsDoiLinkHref = ojsDoiLink.getAttribute('href'); | ||
if (typeof ojsDoiLinkHref === 'string') { | ||
identifiers.push(ojsDoiLinkHref); | ||
} | ||
} | ||
var dois = identifiers.map(parseDoi).filter(isNotNull); | ||
@@ -36,0 +46,0 @@ var uniqueDois = dois.filter(function (doi, index) { return dois.indexOf(doi) === index; }); |
@@ -280,1 +280,17 @@ "use strict"; | ||
}); | ||
describe('Detecting DOIs located in known elements in the <body>', function () { | ||
it('returns DOIs listed for articles on Open Journal Systems', function () { | ||
var dom = new jsdom_1.JSDOM( | ||
// Stripped DOM from an actual OJS site: | ||
"\n <div class=\"pkp_structure_content has_sidebar\">\n <div class=\"pkp_structure_main\" role=\"main\">\n <a id=\"pkp_content_main\"></a>\n <div class=\"page page_article\">\n <article class=\"obj_article_details\">\n <div class=\"row\">\n <div class=\"main_entry\">\n <section class=\"item doi\">\n <h2 class=\"label\">\n DOI:\n </h2>\n <span class=\"value\">\n <a href=\"https://doi.org/10.31219/osf.io/khbvy\">\n https://doi.org/10.31219/osf.io/khbvy\n </a>\n </span>\n </section>\n </div><!-- .main_entry -->\n <!-- .entry_details -->\n </div><!-- .row -->\n </article>\n </div><!-- .page -->\n </div><!-- pkp_structure_main -->\n </div>\n "); | ||
var document = dom.window.document; | ||
expect(index_1.getDois(document)).toEqual(['10.31219/osf.io/khbvy']); | ||
}); | ||
it('does not return a DOI for articles on Open Journal Systems with invalid HTML', function () { | ||
var dom = new jsdom_1.JSDOM( | ||
// Stripped DOM from an actual OJS site: | ||
"\n <div class=\"pkp_structure_content has_sidebar\">\n <div class=\"pkp_structure_main\" role=\"main\">\n <a id=\"pkp_content_main\"></a>\n <div class=\"page page_article\">\n <article class=\"obj_article_details\">\n <div class=\"row\">\n <div class=\"main_entry\">\n <section class=\"item doi\">\n <h2 class=\"label\">\n DOI:\n </h2>\n <span class=\"value\">\n <a data-comment=\"href attribute missing\">\n https://doi.org/10.31219/osf.io/khbvy\n </a>\n </span>\n </section>\n </div><!-- .main_entry -->\n <!-- .entry_details -->\n </div><!-- .row -->\n </article>\n </div><!-- .page -->\n </div><!-- pkp_structure_main -->\n </div>\n "); | ||
var document = dom.window.document; | ||
expect(index_1.getDois(document)).toEqual([]); | ||
}); | ||
}); |
@@ -590,1 +590,73 @@ import { JSDOM } from 'jsdom'; | ||
}); | ||
describe('Detecting DOIs located in known elements in the <body>', () => { | ||
it('returns DOIs listed for articles on Open Journal Systems', () => { | ||
const dom = new JSDOM( | ||
// Stripped DOM from an actual OJS site: | ||
` | ||
<div class="pkp_structure_content has_sidebar"> | ||
<div class="pkp_structure_main" role="main"> | ||
<a id="pkp_content_main"></a> | ||
<div class="page page_article"> | ||
<article class="obj_article_details"> | ||
<div class="row"> | ||
<div class="main_entry"> | ||
<section class="item doi"> | ||
<h2 class="label"> | ||
DOI: | ||
</h2> | ||
<span class="value"> | ||
<a href="https://doi.org/10.31219/osf.io/khbvy"> | ||
https://doi.org/10.31219/osf.io/khbvy | ||
</a> | ||
</span> | ||
</section> | ||
</div><!-- .main_entry --> | ||
<!-- .entry_details --> | ||
</div><!-- .row --> | ||
</article> | ||
</div><!-- .page --> | ||
</div><!-- pkp_structure_main --> | ||
</div> | ||
` | ||
); | ||
const document = dom.window.document; | ||
expect(getDois(document)).toEqual(['10.31219/osf.io/khbvy']); | ||
}); | ||
it('does not return a DOI for articles on Open Journal Systems with invalid HTML', () => { | ||
const dom = new JSDOM( | ||
// Stripped DOM from an actual OJS site: | ||
` | ||
<div class="pkp_structure_content has_sidebar"> | ||
<div class="pkp_structure_main" role="main"> | ||
<a id="pkp_content_main"></a> | ||
<div class="page page_article"> | ||
<article class="obj_article_details"> | ||
<div class="row"> | ||
<div class="main_entry"> | ||
<section class="item doi"> | ||
<h2 class="label"> | ||
DOI: | ||
</h2> | ||
<span class="value"> | ||
<a data-comment="href attribute missing"> | ||
https://doi.org/10.31219/osf.io/khbvy | ||
</a> | ||
</span> | ||
</section> | ||
</div><!-- .main_entry --> | ||
<!-- .entry_details --> | ||
</div><!-- .row --> | ||
</article> | ||
</div><!-- .page --> | ||
</div><!-- pkp_structure_main --> | ||
</div> | ||
` | ||
); | ||
const document = dom.window.document; | ||
expect(getDois(document)).toEqual([]); | ||
}); | ||
}); |
12
index.ts
@@ -39,2 +39,14 @@ import './polyfills'; | ||
const identifiers = metaTagsWithIdentifier.map(tag => tag.getAttribute('content')).filter(isNotNull); | ||
// Open Journal Systems does not necessarily list the DOI in the <head>, | ||
// but if `domTree` includes the <body>, we can at least try to find the link | ||
// there: | ||
const ojsDoiLink = domTree.querySelector('.pkp_structure_main .doi .value a'); | ||
if (ojsDoiLink) { | ||
const ojsDoiLinkHref = ojsDoiLink.getAttribute('href'); | ||
if (typeof ojsDoiLinkHref === 'string') { | ||
identifiers.push(ojsDoiLinkHref); | ||
} | ||
} | ||
const dois = identifiers.map(parseDoi).filter(isNotNull); | ||
@@ -41,0 +53,0 @@ const uniqueDois = dois.filter((doi, index) => dois.indexOf(doi) === index); |
{ | ||
"name": "get-dois", | ||
"version": "3.1.0", | ||
"version": "3.2.0-master-3043577819-9ca4db98", | ||
"description": "Detect Digital Object Identifiers listed in the metadata of a DOM tree", | ||
@@ -40,3 +40,7 @@ "scripts": { | ||
"dependencies": {}, | ||
"peerDependencies": {} | ||
"peerDependencies": {}, | ||
"volta": { | ||
"node": "10.24.1", | ||
"yarn": "1.22.19" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69016
1167
17
1