Skip to content

Build your personal knowledge base with Trilium Notes

chore(icon_pack): return icon mappings

Elian Doran183020a4e3c4
diff --git a/apps/server/src/services/icon_packs.spec.ts b/apps/server/src/services/icon_packs.spec.ts
index 1dd75d71ff..432d964a5f 100644
--- a/apps/server/src/services/icon_packs.spec.ts
+++ b/apps/server/src/services/icon_packs.spec.ts
@@ -1,5 +1,5 @@
import { buildNote } from "../test/becca_easy_mocking";
-import { processIconPack } from "./icon_packs";
+import { IconPackManifest, processIconPack } from "./icon_packs";
describe("Processing icon packs", () => {
it("doesn't crash if icon pack is incorrect type", () => {
@@ -9,4 +9,23 @@ describe("Processing icon packs", () => {
}));
expect(iconPack).toBeFalsy();
});
+
+ it("processes manifest", () => {
+ const manifest: IconPackManifest = {
+ name: "Boxicons v2",
+ prefix: "bx",
+ icons: {
+ "bx-ball": "\ue9c2",
+ "bxs-party": "\uec92"
+ }
+ };
+ const iconPack = processIconPack(buildNote({
+ type: "text",
+ content: JSON.stringify(manifest)
+ }));
+ expect(iconPack?.iconMappings).toMatchObject({
+ "bx-ball": "\ue9c2",
+ "bxs-party": "\uec92"
+ });
+ });
});
diff --git a/apps/server/src/services/icon_packs.ts b/apps/server/src/services/icon_packs.ts
index 1b9ee166c6..0813d709d3 100644
--- a/apps/server/src/services/icon_packs.ts
+++ b/apps/server/src/services/icon_packs.ts
@@ -1,18 +1,25 @@
import type BNote from "../becca/entities/bnote";
import log from "./log";
-interface Manifest {
+export interface IconPackManifest {
name: string;
prefix: string;
icons: Record<string, string>;
}
-export function processIconPack(iconPackNote: BNote) {
- const manifest = iconPackNote.getJsonContentSafely();
+interface ProcessResult {
+ iconMappings: Record<string, string>;
+}
+
+export function processIconPack(iconPackNote: BNote): ProcessResult | undefined {
+ const manifest = iconPackNote.getJsonContentSafely() as IconPackManifest;
if (!manifest) {
log.error(`Icon pack is missing JSON manifest (or has syntax errors): ${iconPackNote.title} (${iconPackNote.noteId})`);
return;
}
- console.log("Got manifest", manifest);
+
+ return {
+ iconMappings: manifest.icons
+ };
}