chore(icon_pack): generate font face declaration without source

This commit is contained in:
Elian Doran 2025-12-26 17:42:44 +02:00
parent 27efa8844e
commit 2f24703690
No known key found for this signature in database
2 changed files with 45 additions and 7 deletions

View File

@ -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'");
});
});

View File

@ -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;
}
`;
}