feat: default note template
feat: item template support more variables
This commit is contained in:
parent
09a03ec456
commit
d358bc2840
|
|
@ -1,5 +1,5 @@
|
|||
import { link } from "fs";
|
||||
import { AddonBase, EditorMessage } from "./base";
|
||||
import { AddonBase, EditorMessage, NoteTemplate } from "./base";
|
||||
|
||||
class AddonEvents extends AddonBase {
|
||||
notifierCallback: object;
|
||||
|
|
@ -791,19 +791,28 @@ class AddonEvents extends AddonBase {
|
|||
}
|
||||
|
||||
const newLines = [];
|
||||
newLines.push("<h1>Imported Items</h1>");
|
||||
newLines.push("<p> </p>");
|
||||
|
||||
const templateText = this._Addon.template.getTemplateByName(
|
||||
message.content.params.templateName
|
||||
).text;
|
||||
|
||||
const toCopyImage = [];
|
||||
|
||||
const copyNoteImage = (noteItem: ZoteroItem) => {
|
||||
toCopyImage.push(noteItem);
|
||||
};
|
||||
|
||||
for (const topItem of items) {
|
||||
/*
|
||||
Available variables:
|
||||
topItem
|
||||
topItem, itemNotes, copyNoteImage
|
||||
*/
|
||||
|
||||
const itemNotes: ZoteroItem[] = topItem
|
||||
.getNotes()
|
||||
.map((e) => Zotero.Items.get(e));
|
||||
|
||||
let _newLine: string = "";
|
||||
try {
|
||||
eval("_newLine = `" + templateText + "`");
|
||||
|
|
@ -815,6 +824,12 @@ class AddonEvents extends AddonBase {
|
|||
newLines.push("<p> </p>");
|
||||
}
|
||||
await this._Addon.knowledge.addLinesToNote(undefined, newLines, -1);
|
||||
const mainNote = this._Addon.knowledge.getWorkspaceNote();
|
||||
await Zotero.DB.executeTransaction(async () => {
|
||||
for (const subNote of toCopyImage) {
|
||||
await Zotero.Notes.copyEmbeddedImages(subNote, mainNote);
|
||||
}
|
||||
});
|
||||
} else if (message.type === "insertNoteUsingTemplate") {
|
||||
/*
|
||||
message.content = {
|
||||
|
|
@ -846,7 +861,6 @@ class AddonEvents extends AddonBase {
|
|||
}
|
||||
|
||||
const newLines = [];
|
||||
newLines.push("<h1>Imported Notes</h1>");
|
||||
newLines.push("<p> </p>");
|
||||
|
||||
const templateText = this._Addon.template.getTemplateByName(
|
||||
|
|
@ -1047,6 +1061,31 @@ class AddonEvents extends AddonBase {
|
|||
|
||||
private resetState(): void {
|
||||
// Reset preferrence state.
|
||||
let templatesRaw: string = Zotero.Prefs.get(
|
||||
"Knowledge4Zotero.noteTemplate"
|
||||
);
|
||||
if (!templatesRaw) {
|
||||
Zotero.Prefs.set(
|
||||
"Knowledge4Zotero.noteTemplate",
|
||||
JSON.stringify([
|
||||
{
|
||||
name: "[Item] item-notes with metadata",
|
||||
text: '<h2 style="color:red; background-color: #efe3da;">💡 Meta Data</h2>\n<table>\n <tr>\n <th style="background-color:#dbeedd;">\n <p style="text-align: right">Title </p>\n </th>\n <td style="background-color:#dbeedd;">\n ${topItem.getField(\'title\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#f3faf4;">\n <p style="text-align: right">Journal </p>\n </th>\n <td style="background-color:#f3faf4;">\n ${topItem.getField(\'publicationTitle\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#dbeedd;">\n <p style="text-align: right">1<sup>st</sup> Author </p>\n </th>\n <td style="background-color:#dbeedd;">\n ${topItem.getField(\'firstCreator\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#f3faf4;">\n <p style="text-align: right">Authors </p>\n </th>\n <td style="background-color:#f3faf4;">\n ${topItem.getCreators().map((v)=>v.firstName+" "+v.lastName).join("; ")}\n </td>\n </tr>\n <tr>\n <th style="background-color:#dbeedd;">\n <p style="text-align: right">Pub. date </p>\n </th>\n <td style="background-color:#dbeedd;">\n ${topItem.getField(\'date\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#f3faf4;">\n <p style="text-align: right">DOI </p>\n </th>\n <td style="background-color:#f3faf4;">\n <a href="https://doi.org/${topItem.getField(\'DOI\')}">${topItem.getField(\'DOI\')}</a>\n </td>\n </tr>\n <tr>\n <th style="background-color:#dbeedd;">\n <p style="text-align: right">Archive </p>\n </th>\n <td style="background-color:#dbeedd;">\n ${topItem.getField(\'archive\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#f3faf4;">\n <p style="text-align: right">Archive Location </p>\n </th>\n <td style="background-color:#f3faf4;">\n ${topItem.getField(\'archiveLocation\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#dbeedd;">\n <p style="text-align: right">Call No. </p>\n </th>\n <td style="background-color:#dbeedd;">\n ${topItem.getField(\'callNumber\')}\n </td>\n </tr>\n</table>\n${itemNotes.map((noteItem)=>{\nconst noteLine = `<h2 style="color:red; background-color: #efe3da;">📜 Note: <a href="zotero://note/${Zotero.Libraries.get(noteItem.libraryID)===\'user\' ? \'u\' : Zotero.Libraries.get(noteItem.libraryID).id}/${noteItem.key}/" rel="noopener noreferrer nofollow">${noteItem.key}</a></h2>\n<blockquote>\n ${noteItem.getNote()}\n <p style="background-color: pink;"><strong>Merge Date: </strong> ${new Date().toISOString().substr(0,10)+" "+ new Date().toTimeString()}</p>\n</blockquote>\n<p style="color:red; background-color: #efe3da;"><strong>📝 Comments</strong></p>\n<blockquote>\n <p>Make your comments</p>\n <p></p>\n</blockquote>`;\ncopyNoteImage(noteItem);\nreturn noteLine;\n}).join("\\n")}\n',
|
||||
disabled: false,
|
||||
},
|
||||
{
|
||||
name: "[Note] with metadata",
|
||||
text: "<p><span style=\"background-color: #ffd40080\">Note: ${link}</span></p>\n${topItem?`<p>Title: ${topItem.getField('title')}</p>\\n<p>Author: ${topItem.getField('firstCreator')}</p>\\n<p>Date: ${topItem.getField('date')}</p>`:''}",
|
||||
disabled: false,
|
||||
},
|
||||
{
|
||||
name: "[Text] today",
|
||||
text: "<h1>TODO: ${new Date().toLocaleDateString()}</h1>\n<h2>Tasks</h2>\n<ul>\n<li>\nRead Paper 1\n</li>\n<li>\nDo some experiments\n</li>\n</ul>\n<blockquote>\n<p>Insert more items with meta-data in workspace window->Edit</p>\n</blockquote>\n<p></p>\n<h2>Done Tasks</h2>\n<p></p>\n<h2>Todo Tomorrow</h2>\n<p></p>\n</div>",
|
||||
disabled: false,
|
||||
},
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue