From 2c4efe085e80fb4ab3b0508f79c9fa0a19e7a243 Mon Sep 17 00:00:00 2001 From: Stefano Pagliari Date: Sat, 14 Jan 2023 09:14:32 +0000 Subject: [PATCH] Fixed bug in citekey export --- package.json | 2 +- src/main.ts | 5 ++++- src/types.ts | 1 + src/utils.ts | 9 +++++++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index d6713ae..38a2d1c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bibnotes", - "version": "0.9.214", + "version": "0.9.215", "description": "Plugin to export and format annotations from Zotero into Obsidian", "main": "main.js", "scripts": { diff --git a/src/main.ts b/src/main.ts index 3b7c72e..9c12d0d 100755 --- a/src/main.ts +++ b/src/main.ts @@ -302,6 +302,9 @@ export default class MyPlugin extends Plugin { } + //Create citekey + selectedEntry.citeKey = selectedEntry.citationKey + //Fix itemType if (selectedEntry.itemType == "journalArticle") { selectedEntry.itemType = "Journal Article" } if (selectedEntry.itemType == "report") { selectedEntry.itemType = "Report" } @@ -371,6 +374,7 @@ export default class MyPlugin extends Plugin { // Create an array with all the fields const entriesArray = Object.keys(selectedEntry); + //replace the single-value placeholders with the value of the field note = replaceAllTemplates(entriesArray, note, selectedEntry); @@ -1842,7 +1846,6 @@ export default class MyPlugin extends Plugin { } extractAnnotation(selectedEntry: Reference, noteTitleFull: string) { - let extractedAnnotations = ""; let extractedAnnotationsYellow = ""; let extractedAnnotationsRed = ""; diff --git a/src/types.ts b/src/types.ts index 6062a3a..1e88f00 100755 --- a/src/types.ts +++ b/src/types.ts @@ -90,6 +90,7 @@ export interface Reference { authorKeyFullName: string; id: number; citationKey: string; + citeKey: string; year: string; citationInLine: string; citationInLineInitials: string; diff --git a/src/utils.ts b/src/utils.ts index f0c5445..f05103c 100755 --- a/src/utils.ts +++ b/src/utils.ts @@ -19,13 +19,18 @@ export function replaceAllTemplates( for (let z = 0; z < entriesArray.length; z++) { // Identify the keyword to be replaced const KW = entriesArray[z]; + console.log(KW) const KW_Brackets = "{{" + KW + "}}"; // replace the keyword in the template + console.log(KW_Brackets) + console.log(`${selectedEntry[KW as keyof Reference]}`) copy = replaceTemplate( copy, KW_Brackets, `${selectedEntry[KW as keyof Reference]}` - ); // fixed the type + ); + console.log(copy) + // fixed the type } return copy; } @@ -220,7 +225,7 @@ export const createAuthorKeyFullName = (creators: CreatorArray) => { if (authorKey.length > 3) { authorKeyFixed = authorKey[0] + " et al."; } - console.log(authorKeyFixed) + if (authorKey.length > 0) { return authorKeyFixed } //If there are no authors (because it is an edited book), then returns the name of the editors