Skip to content

Build your personal knowledge base with Trilium Notes

chore(core): integrate icon usage API

Elian Doran128049b67284
diff --git a/apps/server/src/routes/api/other.ts b/apps/server/src/routes/api/other.ts
index e0a9fd4bce..0b8d852493 100644
--- a/apps/server/src/routes/api/other.ts
+++ b/apps/server/src/routes/api/other.ts
@@ -1,34 +1,9 @@
import type { Request } from "express";
-import becca from "../../becca/becca.js";
import markdownService from "../../services/import/markdown.js";
import markdown from "../../services/export/markdown.js";
import { RenderMarkdownResponse, ToMarkdownResponse } from "@triliumnext/commons";
-function getIconUsage() {
- const iconClassToCountMap: Record<string, number> = {};
-
- for (const { value: iconClass, noteId } of becca.findAttributes("label", "iconClass")) {
- if (noteId.startsWith("_")) {
- continue; // ignore icons of "system" notes since they were not set by the user
- }
-
- if (!iconClass?.trim()) {
- continue;
- }
-
- for (const clazz of iconClass.trim().split(/\s+/)) {
- if (clazz === "bx") {
- continue;
- }
-
- iconClassToCountMap[clazz] = (iconClassToCountMap[clazz] || 0) + 1;
- }
- }
-
- return { iconClassToCountMap };
-}
-
function renderMarkdown(req: Request) {
const { markdownContent } = req.body;
if (!markdownContent || typeof markdownContent !== 'string') {
@@ -50,7 +25,6 @@ function toMarkdown(req: Request) {
}
export default {
- getIconUsage,
renderMarkdown,
toMarkdown
};
diff --git a/apps/server/src/routes/routes.ts b/apps/server/src/routes/routes.ts
index 18b2a771b9..ebd3244f01 100644
--- a/apps/server/src/routes/routes.ts
+++ b/apps/server/src/routes/routes.ts
@@ -302,7 +302,6 @@ function register(app: express.Application) {
apiRoute(GET, "/api/stats/note-size/:noteId", statsRoute.getNoteSize);
apiRoute(GET, "/api/stats/subtree-size/:noteId", statsRoute.getSubtreeSize);
route(GET, "/api/fonts", [auth.checkApiAuthOrElectron], fontsRoute.getFontCss);
- apiRoute(GET, "/api/other/icon-usage", otherRoute.getIconUsage);
apiRoute(PST, "/api/other/render-markdown", otherRoute.renderMarkdown);
apiRoute(PST, "/api/other/to-markdown", otherRoute.toMarkdown);
apiRoute(GET, "/api/recent-changes/:ancestorNoteId", recentChangesApiRoute.getRecentChanges);
diff --git a/packages/trilium-core/src/routes/api/others.ts b/packages/trilium-core/src/routes/api/others.ts
new file mode 100644
index 0000000000..edc4ef63ab
--- /dev/null
+++ b/packages/trilium-core/src/routes/api/others.ts
@@ -0,0 +1,29 @@
+import becca from "../../becca/becca";
+
+function getIconUsage() {
+ const iconClassToCountMap: Record<string, number> = {};
+
+ for (const { value: iconClass, noteId } of becca.findAttributes("label", "iconClass")) {
+ if (noteId.startsWith("_")) {
+ continue; // ignore icons of "system" notes since they were not set by the user
+ }
+
+ if (!iconClass?.trim()) {
+ continue;
+ }
+
+ for (const clazz of iconClass.trim().split(/\s+/)) {
+ if (clazz === "bx") {
+ continue;
+ }
+
+ iconClassToCountMap[clazz] = (iconClassToCountMap[clazz] || 0) + 1;
+ }
+ }
+
+ return { iconClassToCountMap };
+}
+
+export default {
+ getIconUsage
+}
diff --git a/packages/trilium-core/src/routes/index.ts b/packages/trilium-core/src/routes/index.ts
index ee7c69b7c2..7ee403724c 100644
--- a/packages/trilium-core/src/routes/index.ts
+++ b/packages/trilium-core/src/routes/index.ts
@@ -5,6 +5,7 @@ import notesApiRoute from "./api/notes";
import attachmentsApiRoute from "./api/attachments";
import noteMapRoute from "./api/note_map";
import recentNotesRoute from "./api/recent_notes";
+import otherRoute from "./api/others";
import AbstractBeccaEntity from "../becca/entities/abstract_becca_entity";
// TODO: Deduplicate with routes.ts
@@ -58,6 +59,8 @@ export function buildSharedApiRoutes(apiRoute: any) {
apiRoute(GET, "/api/keyboard-actions", keysApiRoute.getKeyboardActions);
apiRoute(GET, "/api/keyboard-shortcuts-for-notes", keysApiRoute.getShortcutsForNotes);
+
+ apiRoute(GET, "/api/other/icon-usage", otherRoute.getIconUsage);
}
/** Handling common patterns. If entity is not caught, serialization to JSON will fail */