Last active
March 22, 2021 21:44
-
-
Save alexjbest/2291889607e292779dd1d9b90d332b8a to your computer and use it in GitHub Desktop.
A zotero translator to export to pretext with pug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"translatorID": "18AAAAAAA9afc-4cd6-8775-1980c3ce0fbf", | |
"label": "Pretext pug export", | |
"creator": "Alex J. Best", | |
"target": "pug", | |
"minVersion": "1.0.0", | |
"maxVersion": "", | |
"priority": 50, | |
"displayOptions": { | |
"exportNotes": true | |
}, | |
"inRepository": true, | |
"translatorType": 2, | |
"lastUpdated":"2019-10-11 07:30:00" | |
} | |
function doExport() { | |
Zotero.setCharacterSet("utf-8"); | |
var pretextpugStrings = []; | |
var item; | |
// eslint-disable-next-line no-cond-assign | |
while (item = Zotero.nextItem()) { | |
var authpart = ""; | |
var auths = item.creators.filter(ii => ii.creatorType == "author"); | |
if (auths === undefined || auths.length == 0) { | |
authpart = encodeURI(item.creators.map(ii => ii.lastName.toLowerCase()).join("-")).replace(/%/g,""); | |
} else { | |
authpart = encodeURI(auths.map(ii => ii.lastName.toLowerCase()).join("-")).replace(/%/g,""); | |
}; | |
var itemString = "biblio#bib-" + authpart + item.date + "(type=\"raw\")\n"; | |
itemString = itemString.replace(/\//g,"-").replace(/ /g, "").replace(/,/g,""); | |
// encode brackets <> | |
itemString += " | \n"; | |
// TODO include editors and stuff somehow | |
for (var j in auths) { | |
itemString += " | " + auths[j].lastName + ", " + auths[j].firstName + ", " + "\n"; | |
} | |
var title = item.title || "[Untitled]"; | |
title = title.replace(/</g, '<').replace(/>/g, '>').replace(/\$(.+?)\$/g,"#[m $1]"); | |
itemString += " title " + title + "\n"; | |
itemString += " | \n"; | |
var eds = item.creators.filter(ii => ii.creatorType == "editor"); | |
if (eds === undefined || eds.length == 0) { } else { | |
itemString += " | In: \n"; | |
for (var j in eds) { | |
itemString += " | " + eds[j].lastName + ", " + eds[j].firstName + ", " + "\n"; | |
itemString += " | \n"; | |
} | |
itemString += " | (eds.)\n"; | |
} | |
/** | |
var dateCreated = item.dateAdded.replace(/[-:]/g, "").replace(" ", "T") + "Z"; | |
itemString += " <created>" + dateCreated + "</created>\n"; | |
var dateUpdated = item.dateModified.replace(/[-:]/g, "").replace(" ", "T") + "Z"; | |
itemString += " <updated>" + dateUpdated + "</updated>\n"; | |
**/ | |
for (var property in item.uniqueFields) { | |
var value = item[property]; | |
if (!value) continue; | |
if (property == "title") { // title | |
} else if (property == "date") { // date | |
itemString += " year " + value + "\n"; | |
itemString += " | \n"; | |
} else if (property == "pages") { // pages | |
itemString += " | pp. " + value + "\n"; | |
itemString += " | \n"; | |
// THE FOLLOWING ARE ALL PART OF THE CONTAINER | |
} else if (property == "publicationTitle") { // Pub title | |
itemString += " journal " + value + "\n"; | |
itemString += " | \n"; | |
} else if (property == "ISSN") { // ISSN | |
itemString += " | ISSN: " + value + "\n"; | |
itemString += " | \n"; | |
} else if (property == "ISBN") { // ISBN | |
itemString += " | ISBN: " + value + "\n"; | |
itemString += " | \n"; | |
} else if (property == "DOI") { // DOI | |
itemString += " | DOI: " + value + "\n"; | |
itemString += " | \n"; | |
//} else if (property == "journalAbbreviation") { // journalAbbreviation | |
// itemString += " journal " + value + "\n"; | |
// itemString += " | \n"; | |
} else if (property == "volume") { // volume | |
itemString += " volume " + value + "\n"; | |
itemString += " | \n"; | |
} else if (property == "issue" || // issue | |
property == "number" || // number | |
property == "patentNumber") { // patentNumber | |
itemString += " number " + value + "\n"; | |
itemString += " | \n"; | |
// THE FOLLOWING ARE ALL PART OF THE SERIES | |
} else if (property == "series") { // series | |
itemString += " | " + value + "\n"; | |
itemString += " | \n"; | |
} else if (property == "seriesTitle") { // seriesTitle | |
itemString += " | " + value + "\n"; | |
itemString += " | \n"; | |
} else if (property == "seriesText") { // seriesText | |
itemString += " | " + value + "\n"; | |
itemString += " | \n"; | |
} else if (property == "seriesNumber") { // seriesNumber | |
itemString += " | " + value + "\n"; | |
itemString += " | \n"; | |
// THE FOLLOWING ARE ALL PART OF THE PUBLISHER | |
} else if (property == "publisher" || // publisher | |
property == "distributor" || // distributor (film) | |
property == "label" || // label (audioRecording) | |
property == "company" || // company (computerProgram) | |
property == "institution") { // institution (report) | |
itemString += " | " + value + "\n"; | |
itemString += " | \n"; | |
} | |
} | |
if (item.url) { | |
itemString += " url(href=\"" + item.url + "\")/\n"; | |
} | |
// replace "&" with "&" | |
itemString = itemString.replace(/&/g, "&"); | |
itemString += "\n"; | |
pretextpugStrings.push(itemString); | |
} | |
Zotero.write(pretextpugStrings.sort().join("")); | |
Zotero.write("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment