mirror of
https://github.com/zadam/trilium.git
synced 2026-01-16 19:44:24 +01:00
chore(core): integrate icon usage API
This commit is contained in:
parent
0eb3cb1118
commit
128049b672
@ -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
|
||||
};
|
||||
|
||||
@ -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);
|
||||
|
||||
29
packages/trilium-core/src/routes/api/others.ts
Normal file
29
packages/trilium-core/src/routes/api/others.ts
Normal file
@ -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
|
||||
}
|
||||
@ -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 */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user