mirror of
https://github.com/zadam/trilium.git
synced 2025-12-29 18:54:29 +01:00
chore(icon_pack): return icon mappings
This commit is contained in:
parent
a56a5fe1f5
commit
183020a4e3
@ -1,5 +1,5 @@
|
||||
import { buildNote } from "../test/becca_easy_mocking";
|
||||
import { processIconPack } from "./icon_packs";
|
||||
import { IconPackManifest, processIconPack } from "./icon_packs";
|
||||
|
||||
describe("Processing icon packs", () => {
|
||||
it("doesn't crash if icon pack is incorrect type", () => {
|
||||
@ -9,4 +9,23 @@ describe("Processing icon packs", () => {
|
||||
}));
|
||||
expect(iconPack).toBeFalsy();
|
||||
});
|
||||
|
||||
it("processes manifest", () => {
|
||||
const manifest: IconPackManifest = {
|
||||
name: "Boxicons v2",
|
||||
prefix: "bx",
|
||||
icons: {
|
||||
"bx-ball": "\ue9c2",
|
||||
"bxs-party": "\uec92"
|
||||
}
|
||||
};
|
||||
const iconPack = processIconPack(buildNote({
|
||||
type: "text",
|
||||
content: JSON.stringify(manifest)
|
||||
}));
|
||||
expect(iconPack?.iconMappings).toMatchObject({
|
||||
"bx-ball": "\ue9c2",
|
||||
"bxs-party": "\uec92"
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,18 +1,25 @@
|
||||
import type BNote from "../becca/entities/bnote";
|
||||
import log from "./log";
|
||||
|
||||
interface Manifest {
|
||||
export interface IconPackManifest {
|
||||
name: string;
|
||||
prefix: string;
|
||||
icons: Record<string, string>;
|
||||
}
|
||||
|
||||
export function processIconPack(iconPackNote: BNote) {
|
||||
const manifest = iconPackNote.getJsonContentSafely();
|
||||
interface ProcessResult {
|
||||
iconMappings: Record<string, string>;
|
||||
}
|
||||
|
||||
export function processIconPack(iconPackNote: BNote): ProcessResult | undefined {
|
||||
const manifest = iconPackNote.getJsonContentSafely() as IconPackManifest;
|
||||
if (!manifest) {
|
||||
log.error(`Icon pack is missing JSON manifest (or has syntax errors): ${iconPackNote.title} (${iconPackNote.noteId})`);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Got manifest", manifest);
|
||||
|
||||
return {
|
||||
iconMappings: manifest.icons
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user