Skip to content

Build your personal knowledge base with Trilium Notes

fix(icon_pack): listing definitions even if parsing fails

Elian Dorana26923cc6da1
diff --git a/apps/server/src/services/icon_packs.spec.ts b/apps/server/src/services/icon_packs.spec.ts
index ffb1a1f36d..b1701d0585 100644
--- a/apps/server/src/services/icon_packs.spec.ts
+++ b/apps/server/src/services/icon_packs.spec.ts
@@ -174,4 +174,21 @@ describe("Icon registery", () => {
]
});
});
+
+ it("ignores incorrect manifest", () => {
+ const iconPack = processIconPack(buildNote({
+ type: "text",
+ content: JSON.stringify({
+ name: "Boxicons v2",
+ prefix: "bx",
+ icons: {
+ "bx-ball": "\ue9c2",
+ "bxs-party": "\uec92"
+ }
+ }),
+ attachments: [ defaultAttachment ]
+ }));
+ const registry = generateIconRegistry([ iconPack! ]);
+ expect(registry.sources).toHaveLength(0);
+ });
});
diff --git a/apps/server/src/services/icon_packs.ts b/apps/server/src/services/icon_packs.ts
index 1b266ad00e..085707a8cc 100644
--- a/apps/server/src/services/icon_packs.ts
+++ b/apps/server/src/services/icon_packs.ts
@@ -43,13 +43,18 @@ export function generateIconRegistry(iconPacks: ProcessResult[]): IconRegistry {
const sources: IconRegistry["sources"] = [];
for (const { manifest } of iconPacks) {
+ const icons: IconRegistry["sources"][number]["icons"] = Object.entries(manifest.icons)
+ .map(( [id, { terms }] ) => {
+ if (!id || !terms) return null;
+ return { id, terms };
+ })
+ .filter(Boolean) as IconRegistry["sources"][number]["icons"];
+ if (!icons.length) continue;
+
sources.push({
prefix: manifest.prefix,
name: manifest.name,
- icons: Object.entries(manifest.icons).map(( [id, { terms }] ) => ({
- id,
- terms
- }))
+ icons
});
}