Skip to content

Build your personal knowledge base with Trilium Notes

chore(icon_pack): switch schema to support multiple terms per icon

Elian Doran254511bfbfa3
diff --git a/apps/client/src/types.d.ts b/apps/client/src/types.d.ts
index c12ed615c1..4572c4030c 100644
--- a/apps/client/src/types.d.ts
+++ b/apps/client/src/types.d.ts
@@ -1,3 +1,5 @@
+import { IconRegistry } from "@triliumnext/commons";
+
import appContext, { AppContext } from "./components/app_context";
import type FNote from "./entities/fnote";
import type { PrintReport } from "./print";
@@ -46,6 +48,7 @@ interface CustomGlobals {
linter: typeof lint;
hasNativeTitleBar: boolean;
isRtl: boolean;
+ iconRegistry: IconRegistry;
}
type RequireMethod = (moduleName: string) => any;
diff --git a/apps/server/src/services/icon_packs.spec.ts b/apps/server/src/services/icon_packs.spec.ts
index 7a26cba698..ffb1a1f36d 100644
--- a/apps/server/src/services/icon_packs.spec.ts
+++ b/apps/server/src/services/icon_packs.spec.ts
@@ -5,8 +5,14 @@ const manifest: IconPackManifest = {
name: "Boxicons v2",
prefix: "bx",
icons: {
- "bx-ball": "\ue9c2",
- "bxs-party": "\uec92"
+ "bx-ball": {
+ glyph: "\ue9c2",
+ terms: [ "ball" ]
+ },
+ "bxs-party": {
+ glyph: "\uec92",
+ terms: [ "party" ]
+ }
}
};
@@ -108,8 +114,14 @@ describe("CSS generation", () => {
name: "Boxicons v2",
prefix: "bx",
icons: {
- "bx-ball": "\ue9c2",
- "bxs-party": "\uec92"
+ "bx-ball": {
+ "glyph": "\ue9c2",
+ "terms": [ "ball" ]
+ },
+ "bxs-party": {
+ "glyph": "\uec92",
+ "terms": [ "party" ]
+ }
}
};
const processedResult = processIconPack(buildNote({
@@ -153,11 +165,11 @@ describe("Icon registery", () => {
icons: [
{
id: "bx-ball",
- label: "ball"
+ terms: [ "ball" ]
},
{
id: "bxs-party",
- label: "party"
+ terms: [ "party" ]
}
]
});
diff --git a/apps/server/src/services/icon_packs.ts b/apps/server/src/services/icon_packs.ts
index 946e3cfd7d..4d77eddaa5 100644
--- a/apps/server/src/services/icon_packs.ts
+++ b/apps/server/src/services/icon_packs.ts
@@ -20,7 +20,10 @@ const MIME_TO_CSS_FORMAT_MAPPINGS: Record<typeof PREFERRED_MIME_TYPE[number], st
export interface IconPackManifest {
name: string;
prefix: string;
- icons: Record<string, string>;
+ icons: Record<string, {
+ glyph: string,
+ terms: string[];
+ }>;
}
interface ProcessResult {
@@ -42,9 +45,9 @@ export function generateIconRegistry(iconPacks: ProcessResult[]): IconRegistry {
sources.push({
prefix: manifest.prefix,
name: manifest.name,
- icons: Object.keys(manifest.icons).map(id => ({
+ icons: Object.entries(manifest.icons).map(( [id, { terms }] ) => ({
id,
- label: id.split("-").at(-1) ?? id
+ terms
}))
});
}
@@ -91,7 +94,7 @@ export function determineBestFontAttachment(iconPackNote: BNote) {
export function generateCss({ manifest, fontAttachmentId, fontMime }: ProcessResult) {
const iconDeclarations: string[] = [];
for (const [ key, mapping ] of Object.entries(manifest.icons)) {
- iconDeclarations.push(`.${manifest.prefix}.${key}::before { content: '\\${mapping.charCodeAt(0).toString(16)}'; }`);
+ iconDeclarations.push(`.${manifest.prefix}.${key}::before { content: '\\${mapping.glyph.charCodeAt(0).toString(16)}'; }`);
}
return `\
diff --git a/packages/commons/src/lib/server_api.ts b/packages/commons/src/lib/server_api.ts
index 3f3d706f87..d5a76929f4 100644
--- a/packages/commons/src/lib/server_api.ts
+++ b/packages/commons/src/lib/server_api.ts
@@ -292,7 +292,7 @@ export interface IconRegistry {
name: string;
icons: {
id: string;
- label: string;
+ terms: string[];
}[]
}[];
}