Skip to content

Build your personal knowledge base with Trilium Notes

chore(icon_pack): generate font face declaration without source

Elian Doran2f24703690a9
diff --git a/apps/server/src/services/icon_packs.spec.ts b/apps/server/src/services/icon_packs.spec.ts
index 02b7bef83a..4f41258b44 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 { determineBestFontAttachment, IconPackManifest, processIconPack } from "./icon_packs";
+import { determineBestFontAttachment, generateCss, IconPackManifest, processIconPack } from "./icon_packs";
describe("Processing icon packs", () => {
it("doesn't crash if icon pack is incorrect type", () => {
@@ -23,10 +23,7 @@ describe("Processing icon packs", () => {
type: "text",
content: JSON.stringify(manifest)
}));
- expect(iconPack?.iconMappings).toMatchObject({
- "bx-ball": "\ue9c2",
- "bxs-party": "\uec92"
- });
+ expect(iconPack?.manifest).toMatchObject(manifest);
});
});
@@ -101,3 +98,34 @@ describe("Mapping attachments", () => {
expect(attachment?.mime).toStrictEqual("font/woff2");
});
});
+
+describe("CSS generation", () => {
+ it("generates the CSS", () => {
+ const manifest: IconPackManifest = {
+ name: "Boxicons v2",
+ prefix: "bx",
+ icons: {
+ "bx-ball": "\ue9c2",
+ "bxs-party": "\uec92"
+ }
+ };
+ const iconPackNote = buildNote({
+ type: "text",
+ content: JSON.stringify(manifest),
+ attachments: [
+ {
+ role: "file",
+ title: "Font",
+ mime: "font/woff2"
+ }
+ ]
+ });
+ const processedResult = processIconPack(iconPackNote);
+ expect(processedResult).toBeTruthy();
+ const css = generateCss(processedResult!, iconPackNote);
+
+ console.log(css);
+ expect(css).toContain("@font-face");
+ expect(css).toContain("font-family: 'trilium-icon-pack-bx'");
+ });
+});
diff --git a/apps/server/src/services/icon_packs.ts b/apps/server/src/services/icon_packs.ts
index 033c0c5597..a9fbaa7471 100644
--- a/apps/server/src/services/icon_packs.ts
+++ b/apps/server/src/services/icon_packs.ts
@@ -15,7 +15,7 @@ export interface IconPackManifest {
}
interface ProcessResult {
- iconMappings: Record<string, string>;
+ manifest: IconPackManifest;
}
export function processIconPack(iconPackNote: BNote): ProcessResult | undefined {
@@ -26,7 +26,7 @@ export function processIconPack(iconPackNote: BNote): ProcessResult | undefined
}
return {
- iconMappings: manifest.icons
+ manifest
};
}
@@ -45,3 +45,13 @@ export function determineBestFontAttachment(iconPackNote: BNote) {
return null;
}
+
+export function generateCss(processedIconPack: ProcessResult, iconPackNote: BNote) {
+ return `\
+ @font-face {
+ font-family: 'trilium-icon-pack-${processedIconPack.manifest.prefix}';
+ font-weight: normal;
+ font-style: normal;
+ }
+ `;
+}