Skip to content

Commit

Permalink
Make EM the generic translator. Addresses zotero#1092
Browse files Browse the repository at this point in the history
  • Loading branch information
adomasven committed Oct 3, 2017
1 parent 08a0389 commit 21dbb16
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 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": "2017-08-26 11:30:00"
"lastUpdated": "2017-10-03 01:32:00"
}

/*
Expand Down Expand Up @@ -209,12 +209,40 @@ function completeItem(doc, newItem) {
newItem.complete();
}

/**
* This is a short-term hacky solution to make EM the generic translator.
*
* After running init() if _itemType == undefined it means EM can only
* capture (somewhat) low quality metadata. If there are no translators with lower priority
* that detect any metadata then EM detectWeb should return "webpage", otherwise
* return undefined and let lower priority translators overtake.
*
* See discussion https://github.com/zotero/translators/issues/1092
*
* N.B. this function needs to check *ALL* translators with lower priority than EM
* and ensure that `false` is passed back as a callback if any one of them detects
* metadata, otherwise EM with low quality translation will overshadow them
*/
function checkLowerPriorityTranslators(doc, url, callback) {
if (_itemType != undefined) return callback(_itemType);

var translate = Zotero.loadTranslator("web");
// DOI
translate.setTranslator("c159dcfe-8a53-4301-a499-30f6549c340d");
translate.getTranslatorObject(function(translator) {
if (!translator.detectWeb(doc, url)) {
return callback('webpage');
}
callback(false);
});
}

function detectWeb(doc, url) {
//blacklist wordpress jetpack comment plugin so it doesn't override other metadata
if (url.indexOf("jetpack.wordpress.com/jetpack-comment/")!=-1) return false;
if(exports.itemType) return exports.itemType;

init(doc, url, Zotero.done);
init(doc, url, checkLowerPriorityTranslators.bind(this, doc, url, Zotero.done));
}

function init(doc, url, callback, forceLoadRDF) {
Expand Down Expand Up @@ -360,7 +388,7 @@ function doWeb(doc, url) {
function importRDF(doc, url) {
RDF.doImport();
if(!_haveItem) {
completeItem(doc, new Zotero.Item(_itemType));
completeItem(doc, new Zotero.Item(_itemType || 'webpage'));
}
}

Expand Down

0 comments on commit 21dbb16

Please sign in to comment.