From 5f1bdf726491de40475199901a9669e05c2f13b3 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 26 Dec 2025 18:15:46 +0200 Subject: [PATCH] chore(icon_pack): generate icon declarations --- apps/server/src/services/icon_packs.spec.ts | 2 ++ apps/server/src/services/icon_packs.ts | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/server/src/services/icon_packs.spec.ts b/apps/server/src/services/icon_packs.spec.ts index 16ea35e2a..0da99d4c0 100644 --- a/apps/server/src/services/icon_packs.spec.ts +++ b/apps/server/src/services/icon_packs.spec.ts @@ -133,5 +133,7 @@ describe("CSS generation", () => { expect(css).toContain("@font-face"); expect(css).toContain("font-family: 'trilium-icon-pack-bx' !important;"); + expect(css).toContain(".bx.bx-ball::before { content: '\\e9c2'; }"); + expect(css).toContain(".bx.bxs-party::before { content: '\\ec92'; }"); }); }); diff --git a/apps/server/src/services/icon_packs.ts b/apps/server/src/services/icon_packs.ts index 16a63ac25..daa327a8d 100644 --- a/apps/server/src/services/icon_packs.ts +++ b/apps/server/src/services/icon_packs.ts @@ -62,17 +62,22 @@ export function determineBestFontAttachment(iconPackNote: BNote) { return null; } -export function generateCss(processedIconPack: ProcessResult) { +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)}' }`); + } + return `\ @font-face { - font-family: 'trilium-icon-pack-${processedIconPack.manifest.prefix}'; + font-family: 'trilium-icon-pack-${manifest.prefix}'; font-weight: normal; font-style: normal; - src: url('/api/attachments/${processedIconPack.fontAttachmentId}/download') format('${MIME_TO_CSS_FORMAT_MAPPINGS[processedIconPack.fontMime]}'); + src: url('/api/attachments/${fontAttachmentId}/download') format('${MIME_TO_CSS_FORMAT_MAPPINGS[fontMime]}'); } - .${processedIconPack.manifest.prefix} { - font-family: 'trilium-icon-pack-${processedIconPack.manifest.prefix}' !important; + .${manifest.prefix} { + font-family: 'trilium-icon-pack-${manifest.prefix}' !important; font-weight: normal; font-style: normal; font-variant: normal; @@ -83,5 +88,7 @@ export function generateCss(processedIconPack: ProcessResult) { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } + + ${iconDeclarations.join("\n")} `; }