mirror of
https://github.com/zadam/trilium.git
synced 2025-12-31 11:44:23 +01:00
chore(icon_pack): generate font face declaration without source
This commit is contained in:
parent
27efa8844e
commit
2f24703690
@ -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'");
|
||||
});
|
||||
});
|
||||
|
||||
@ -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;
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user