Skip to content

Build your personal knowledge base with Trilium Notes

feat(templates): add support for built-in templates

Elian Doranfa112956933b
diff --git a/apps/client/src/services/note_types.ts b/apps/client/src/services/note_types.ts
index 4de0bd8bfb..b8d0578697 100644
--- a/apps/client/src/services/note_types.ts
+++ b/apps/client/src/services/note_types.ts
@@ -4,6 +4,8 @@ import { t } from "./i18n.js";
import type { MenuItem } from "../menus/context_menu.js";
import type { TreeCommandNames } from "../menus/tree_context_menu.js";
+const SEPARATOR = { title: "----" };
+
async function getNoteTypeItems(command?: TreeCommandNames) {
const items: MenuItem<TreeCommandNames>[] = [
{ title: t("note_types.text"), command, type: "text", uiIcon: "bx bx-note" },
@@ -18,6 +20,7 @@ async function getNoteTypeItems(command?: TreeCommandNames) {
{ title: t("note_types.web-view"), command, type: "webView", uiIcon: "bx bx-globe-alt" },
{ title: t("note_types.mind-map"), command, type: "mindMap", uiIcon: "bx bx-sitemap" },
{ title: t("note_types.geo-map"), command, type: "geoMap", uiIcon: "bx bx-map-alt" },
+ ...await getBuiltInTemplates(command)
];
const templateNoteIds = await server.get<string[]>("search-templates");
@@ -40,6 +43,33 @@ async function getNoteTypeItems(command?: TreeCommandNames) {
return items;
}
+async function getBuiltInTemplates(command?: TreeCommandNames) {
+ const templatesRoot = await froca.getNote("_templates");
+ if (!templatesRoot) {
+ console.warn("Unable to find template root.");
+ return [];
+ }
+
+ const childNotes = await templatesRoot.getChildNotes();
+ if (childNotes.length === 0) {
+ return [];
+ }
+
+ const items: MenuItem<TreeCommandNames>[] = [
+ SEPARATOR
+ ];
+ for (const templateNote of childNotes) {
+ items.push({
+ title: templateNote.title,
+ uiIcon: templateNote.getIcon(),
+ command: command,
+ type: templateNote.type,
+ templateNoteId: templateNote.noteId
+ });
+ }
+ return items;
+}
+
export default {
getNoteTypeItems
};
diff --git a/apps/server/src/services/hidden_subtree.ts b/apps/server/src/services/hidden_subtree.ts
index 02c7b90f0c..6ba0d965b3 100644
--- a/apps/server/src/services/hidden_subtree.ts
+++ b/apps/server/src/services/hidden_subtree.ts
@@ -8,6 +8,7 @@ import migrationService from "./migration.js";
import { t } from "i18next";
import { cleanUpHelp, getHelpHiddenSubtreeData } from "./in_app_help.js";
import buildLaunchBarConfig from "./hidden_subtree_launcherbar.js";
+import buildHiddenSubtreeTemplates from "./hidden_subtree_templates.js";
const LBTPL_ROOT = "_lbTplRoot";
const LBTPL_BASE = "_lbTplBase";
@@ -257,7 +258,8 @@ function buildHiddenSubtreeDefinition(helpSubtree: HiddenSubtreeItem[]): HiddenS
icon: "bx-help-circle",
children: helpSubtree,
isExpanded: true
- }
+ },
+ buildHiddenSubtreeTemplates()
]
};
}
diff --git a/apps/server/src/services/hidden_subtree_templates.ts b/apps/server/src/services/hidden_subtree_templates.ts
new file mode 100644
index 0000000000..8e4a628a45
--- /dev/null
+++ b/apps/server/src/services/hidden_subtree_templates.ts
@@ -0,0 +1,28 @@
+import { HiddenSubtreeItem } from "@triliumnext/commons";
+
+export default function buildHiddenSubtreeTemplates() {
+ const templates: HiddenSubtreeItem = {
+ id: "_templates",
+ title: "Built-in templates",
+ type: "book",
+ children: [
+ {
+ id: "_template_text_snippet",
+ type: "text",
+ title: "Text Snippet",
+ attributes: [
+ {
+ name: "template",
+ type: "label"
+ },
+ {
+ name: "textSnippet",
+ type: "label"
+ }
+ ]
+ }
+ ]
+ };
+
+ return templates;
+}