chore(icon_pack): switch schema to support multiple terms per icon

This commit is contained in:
Elian Doran
2025-12-26 19:25:31 +02:00
parent e2f6f8a4e4
commit 254511bfbf
4 changed files with 29 additions and 11 deletions

View File

@@ -1,3 +1,5 @@
import { IconRegistry } from "@triliumnext/commons";
import appContext, { AppContext } from "./components/app_context";
import type FNote from "./entities/fnote";
import type { PrintReport } from "./print";
@@ -46,6 +48,7 @@ interface CustomGlobals {
linter: typeof lint;
hasNativeTitleBar: boolean;
isRtl: boolean;
iconRegistry: IconRegistry;
}
type RequireMethod = (moduleName: string) => any;

View File

@@ -5,8 +5,14 @@ const manifest: IconPackManifest = {
name: "Boxicons v2",
prefix: "bx",
icons: {
"bx-ball": "\ue9c2",
"bxs-party": "\uec92"
"bx-ball": {
glyph: "\ue9c2",
terms: [ "ball" ]
},
"bxs-party": {
glyph: "\uec92",
terms: [ "party" ]
}
}
};
@@ -108,8 +114,14 @@ describe("CSS generation", () => {
name: "Boxicons v2",
prefix: "bx",
icons: {
"bx-ball": "\ue9c2",
"bxs-party": "\uec92"
"bx-ball": {
"glyph": "\ue9c2",
"terms": [ "ball" ]
},
"bxs-party": {
"glyph": "\uec92",
"terms": [ "party" ]
}
}
};
const processedResult = processIconPack(buildNote({
@@ -153,11 +165,11 @@ describe("Icon registery", () => {
icons: [
{
id: "bx-ball",
label: "ball"
terms: [ "ball" ]
},
{
id: "bxs-party",
label: "party"
terms: [ "party" ]
}
]
});

View File

@@ -20,7 +20,10 @@ const MIME_TO_CSS_FORMAT_MAPPINGS: Record<typeof PREFERRED_MIME_TYPE[number], st
export interface IconPackManifest {
name: string;
prefix: string;
icons: Record<string, string>;
icons: Record<string, {
glyph: string,
terms: string[];
}>;
}
interface ProcessResult {
@@ -42,9 +45,9 @@ export function generateIconRegistry(iconPacks: ProcessResult[]): IconRegistry {
sources.push({
prefix: manifest.prefix,
name: manifest.name,
icons: Object.keys(manifest.icons).map(id => ({
icons: Object.entries(manifest.icons).map(( [id, { terms }] ) => ({
id,
label: id.split("-").at(-1) ?? id
terms
}))
});
}
@@ -91,7 +94,7 @@ export function determineBestFontAttachment(iconPackNote: BNote) {
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)}'; }`);
iconDeclarations.push(`.${manifest.prefix}.${key}::before { content: '\\${mapping.glyph.charCodeAt(0).toString(16)}'; }`);
}
return `\

View File

@@ -292,7 +292,7 @@ export interface IconRegistry {
name: string;
icons: {
id: string;
label: string;
terms: string[];
}[]
}[];
}