Skip to content

Commit

Permalink
Embedded Metadata: Fix regression in 8d2ee28
Browse files Browse the repository at this point in the history
This was breaking some versions of NYT pages (and possibly lots of other
stuff):

zotero/translation-server#133 (comment)
  • Loading branch information
dstillman committed Nov 7, 2021
1 parent 9600579 commit 0d435d8
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions Embedded Metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2021-10-22 00:24:00"
"lastUpdated": "2021-11-07 07:42:50"
}

/*
Expand Down Expand Up @@ -468,15 +468,21 @@ function addHighwireMetadata(doc, newItem, hwType) {

// matches hyphens and en-dashes
let dashRe = /[-\u2013]/g;
var firstpage = getContentText(doc, 'citation_firstpage').replace(dashRe, '-');
var lastpage = getContentText(doc, 'citation_lastpage').replace(dashRe, '-');
if (firstpage && firstpage.includes("-")) {
firstpage = firstpage.split(/\s*-\s*/)[0];
lastpage = lastpage || firstpage.split(/\s*-\s*/)[1];
var firstpage = getContentText(doc, 'citation_firstpage');
var lastpage = getContentText(doc, 'citation_lastpage');
if (firstpage) {
firstpage = firstpage.replace(dashRe, '-');
if (firstpage.includes("-")) {
firstpage = firstpage.split(/\s*-\s*/)[0];
lastpage = lastpage || firstpage.split(/\s*-\s*/)[1];
}
}
if (lastpage && lastpage.includes('-')) {
firstpage = firstpage || lastpage.split(/\s*-\s*/)[0];
lastpage = lastpage.split(/\s*-\s*/)[1];
if (lastpage) {
lastpage = lastpage.replace(dashRe, '-');
if (lastpage.includes('-')) {
firstpage = firstpage || lastpage.split(/\s*-\s*/)[0];
lastpage = lastpage.split(/\s*-\s*/)[1];
}
}
firstpage = firstpage || rdfPages[0];
lastpage = lastpage || rdfPages[1];
Expand Down

0 comments on commit 0d435d8

Please sign in to comment.