From d8e29cedc8deffa5649db9cee11483601c895659 Mon Sep 17 00:00:00 2001 From: windingwind <33902321+windingwind@users.noreply.github.com> Date: Thu, 28 Mar 2024 21:01:22 +0800 Subject: [PATCH] fix: template preview --- src/modules/template/preview.ts | 65 ++++++++++++++++----------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/src/modules/template/preview.ts b/src/modules/template/preview.ts index 8f76010..d5a0440 100644 --- a/src/modules/template/preview.ts +++ b/src/modules/template/preview.ts @@ -78,16 +78,15 @@ async function renderTemplatePreview( const link = getNoteLink(data); const linkText = data.getNoteTitle().trim() || link; const subNoteItem = data; - return ""; - // const noteItem = Zotero.Items.get(addon.data.workspace.mainId); - // html = await addon.api.template.runTemplate( - // templateName, - // "link, linkText, subNoteItem, noteItem", - // [link, linkText, subNoteItem, noteItem], - // { - // dryRun: true, - // }, - // ); + const noteItem = new Zotero.Item("note"); + html = await addon.api.template.runTemplate( + templateName, + "link, linkText, subNoteItem, noteItem", + [link, linkText, subNoteItem, noteItem], + { + dryRun: true, + }, + ); } } else if (templateName.includes("QuickBackLink")) { // link, linkText, subNoteItem, noteItem @@ -95,19 +94,18 @@ async function renderTemplatePreview( if (!data) { html = "

No note item selected

"; } else { - return ""; - // const link = getNoteLink(data); - // const noteItem = Zotero.Items.get(addon.data.workspace.mainId); - // const linkText = noteItem.getNoteTitle().trim() || "Workspace Note"; - // const subNoteItem = data; - // html = await addon.api.template.runTemplate( - // templateName, - // "link, linkText, subNoteItem, noteItem", - // [link, linkText, subNoteItem, noteItem], - // { - // dryRun: true, - // }, - // ); + const link = getNoteLink(data); + const noteItem = new Zotero.Item("note"); + const linkText = noteItem.getNoteTitle().trim() || "Workspace Note"; + const subNoteItem = data; + html = await addon.api.template.runTemplate( + templateName, + "link, linkText, subNoteItem, noteItem", + [link, linkText, subNoteItem, noteItem], + { + dryRun: true, + }, + ); } } else if (templateName.includes("QuickImport")) { // link, noteItem @@ -115,17 +113,16 @@ async function renderTemplatePreview( if (!data) { html = "

No note item selected

"; } else { - return ""; - // const link = getNoteLink(data); - // const noteItem = Zotero.Items.get(addon.data.workspace.mainId); - // html = await addon.api.template.runTemplate( - // templateName, - // "link, noteItem", - // [link, noteItem], - // { - // dryRun: true, - // }, - // ); + const link = getNoteLink(data); + const noteItem = new Zotero.Item("note"); + html = await addon.api.template.runTemplate( + templateName, + "link, noteItem", + [link, noteItem], + { + dryRun: true, + }, + ); } } else if (templateName.includes("QuickNote")) { // annotationItem, topItem, noteItem