Last active
October 23, 2022 19:09
-
-
Save joshjhall/8ed13e964f1b7f3551908c576ef4f5d2 to your computer and use it in GitHub Desktop.
Zotero exporter optimized for Tana paste. This is just building on others' work. Importantly, I've added some additional protections for missing data, and created a switch statement to tweak the internal Zotero type schema to better fit my use-cases. Feel free to use or modify as you see fit.
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":"dda092d2-a257-46af-b9a3-2f04a55cb04f", | |
"translatorType":2, | |
"label":"Tana Metadata Export", | |
"creator":"Joshua Hall based upon Stian Håklev, Joel Chan, and Lukas Kawerau's work", | |
"target":"md", | |
"minVersion":"2.0", | |
"maxVersion":"", | |
"priority":200, | |
"inRepository":false, | |
"lastUpdated":"2022-10-23 - 14:15" | |
} | |
function doExport() { | |
Zotero.write('%%tana%%\n'); | |
var item; | |
while (item = Zotero.nextItem()) { | |
// Set the type | |
var typeS = null; | |
if (item.itemType !== undefined) { | |
switch(item.itemType) { | |
case 'journalArticle': | |
case 'conferencePaper': | |
typeS = 'journal article'; | |
break; | |
case 'tvBroadcast': | |
case 'videoRecording': | |
typeS = 'video'; | |
break; | |
case 'encyclopediaArticle': | |
case 'magazineArticle': | |
case 'newspaperArticle': | |
case 'webpage': | |
typeS = 'article'; | |
break; | |
case 'blogPost': | |
typeS = 'blog'; | |
break; | |
case 'audioRecording': | |
typeS = 'interview'; | |
break; | |
case 'manuscript': | |
case 'bookSection': | |
typeS = 'book'; | |
break; | |
// case 'annotation': | |
// case 'artwork': | |
// case 'attachment': | |
// case 'bill': | |
// case 'book': | |
// case 'case': | |
// case 'computerProgram': | |
// case 'dictionaryEntry': | |
// case 'document': | |
// case 'email': | |
// case 'film': | |
// case 'forumPost': | |
// case 'hearing': | |
// case 'instantMessage': | |
// case 'interview': | |
// case 'letter': | |
// case 'map': | |
// case 'patent': | |
// case 'podcast': | |
// case 'preprint': | |
// case 'presentation': | |
// case 'radioBroadcast': | |
// case 'report': | |
// case 'statute': | |
// case 'thesis': | |
default: | |
// Pass through anything not specified here | |
typeS = item.itemType; | |
} | |
typeS = ' #[[' + typeS + ']]'; | |
} | |
// Write the title and type | |
Zotero.write('- ' + (item.title || 'Unknown title') + (typeS || '') + '\n'); | |
// --- | |
// Set citekey | |
if (item.citationKey !== undefined && item.citationKey !== '') { | |
// Preferred citation key reference syntax | |
var citationKeyS = '@' + item.citationKey; | |
// Write the citation key | |
Zotero.write(' - Citation key:: ' + citationKeyS + '\n'); | |
} | |
// --- | |
// Set the author list | |
if (item.creators !== undefined) { | |
Zotero.write(' - Author::\n'); | |
for (author in item.creators){ | |
if (item.creators[author].firstName !== undefined && item.creators[author].lastName !== undefined) { | |
// Use the full name of the author. Should be the most common situation | |
Zotero.write(' - [[' + (item.creators[author].firstName || '') + ' ' + (item.creators[author].lastName || '') + ']] #[[author]]\n'); | |
} else if (item.creators[author].lastName !== undefined) { | |
// Only use the last name | |
Zotero.write(' - [[' (item.creators[author].lastName || '') + ']] #[[author]]\n'); | |
} else { | |
// Hypothetically impossible unless your DB is inconsistent for some reason | |
Zotero.write(' - Unknown author'); | |
} | |
} | |
Zotero.write('\n'); | |
} | |
// --- | |
// Set the year | |
var date = Zotero.Utilities.strToDate(item.date); | |
var dateS = (date.year) ? date.year : item.date; | |
if (dateS !== undefined && dateS !== '') { | |
// Write the year | |
Zotero.write(' - Year:: ' + dateS + '\n'); | |
} | |
// --- | |
// Set the publication | |
if (item.publicationTitle !== undefined) { | |
Zotero.write(' - Publication:: ' + (item.publicationTitle || '') + '\n'); | |
} | |
// --- | |
// Set the Zotero link | |
var library_id = item.libraryID ? item.libraryID : 0; | |
var itemLink = 'zotero://select/items/' + library_id + '_' + item.key; | |
Zotero.write(' - Zotero link:: ' + itemLink + '\n'); | |
// --- | |
// Set the URL for the source | |
if (item.url !== undefined) { | |
Zotero.write(' - URL:: ' + (item.url || '') + '\n'); | |
} | |
// --- | |
// Set the abstract summary | |
if (item.abstractNote !== undefined) { | |
Zotero.write(' - Abstract:: '+ (item.abstractNote || '')+ '\n'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Still a work in progress, but this adds some important protections against missing data that's caused me problems in the past.