Skip to content

Commit

Permalink
Code refactored
Browse files Browse the repository at this point in the history
Should have any problems now with undefined or invalid fields.
  • Loading branch information
silentdot authored Oct 14, 2020
1 parent 494a2f8 commit c41849b
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions Markdown Item URI.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
{
"translatorID":"8dbf9b92-f796-4153-8f2e-ac6c157500dc",
"translatorType":2,
"label":"Markdown Item URI",
"creator":"Silent",
"target":"markdown",
"minVersion":"2.0",
"maxVersion":"",
"priority":200,
"inRepository":false,
"lastUpdated":"2020-10-13"
}


function doExport() {
var item;
while(item = Zotero.nextItem()) {

Zotero.write("["+item.creators[0].lastName+". "+item.date+". *"+ item["title"] + "*]")
Zotero.write("(zotero://select/items/");
var library_id = item.libraryID ? item.libraryID : 0;
Zotero.write(library_id+"_"+item.key+")");
"translatorID":"8dbf9b92-f796-4153-8f2e-ac6c157500dc",
"translatorType":2,
"label":"Markdown Item URI",
"creator":"Silent",
"target":"markdown",
"minVersion":"2.0",
"maxVersion":"",
"priority":200,
"inRepository":false,
"lastUpdated":"2020-10-15"
}
}


function doExport() {
var item;
while(item = Zotero.nextItem()) {
var date = new Date(item.date).getFullYear()

var year = date && !isNaN(date) ? date + ". " : (typeof item.date == 'undefined'? "" : item.date + ". ");
var library_id = item.libraryID ? item.libraryID : "";
var author_lastname = item.creators[0].lastName ? item.creators[0].lastName + ". " : "";
var title = item.title ? "*" + item.title + "*" : "";
var key = item.key;

Zotero.write(`[${author_lastname}${year}${title}](zotero://select/items/${library_id}_${key})`)
}
}

0 comments on commit c41849b

Please sign in to comment.