mirror of
https://github.com/zadam/trilium.git
synced 2025-12-27 10:39:56 +01:00
feat(icon_pack): generate icon registry for client
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
platform: "<%= platform %>",
|
||||
hasNativeTitleBar: <%= hasNativeTitleBar %>,
|
||||
TRILIUM_SAFE_MODE: <%= !!process.env.TRILIUM_SAFE_MODE %>,
|
||||
isRtl: <%= !!currentLocale.rtl %>
|
||||
isRtl: <%= !!currentLocale.rtl %>,
|
||||
iconRegistry: <%- JSON.stringify(iconRegistry) %>
|
||||
};
|
||||
</script>
|
||||
@@ -7,7 +7,7 @@ import assetPath from "../services/asset_path.js";
|
||||
import attributeService from "../services/attributes.js";
|
||||
import config from "../services/config.js";
|
||||
import { getCurrentLocale } from "../services/i18n.js";
|
||||
import { generateCss, getIconPacks } from "../services/icon_packs.js";
|
||||
import { generateCss, generateIconRegistry, getIconPacks } from "../services/icon_packs.js";
|
||||
import log from "../services/log.js";
|
||||
import optionService from "../services/options.js";
|
||||
import protectedSessionService from "../services/protected_session.js";
|
||||
@@ -62,7 +62,8 @@ function index(req: Request, res: Response) {
|
||||
appPath,
|
||||
baseApiUrl: 'api/',
|
||||
currentLocale: getCurrentLocale(),
|
||||
iconPackCss: iconPacks.map(p => generateCss(p)).join("\n\n")
|
||||
iconPackCss: iconPacks.map(p => generateCss(p)).join("\n\n"),
|
||||
iconRegistry: generateIconRegistry(iconPacks)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { buildNote } from "../test/becca_easy_mocking";
|
||||
import { determineBestFontAttachment, generateCss, IconPackManifest, processIconPack } from "./icon_packs";
|
||||
import { determineBestFontAttachment, generateCss, generateIconRegistry, IconPackManifest, processIconPack } from "./icon_packs";
|
||||
|
||||
const manifest: IconPackManifest = {
|
||||
name: "Boxicons v2",
|
||||
@@ -137,3 +137,29 @@ describe("CSS generation", () => {
|
||||
expect(css).toContain(".bx.bxs-party::before { content: '\\ec92'; }");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Icon registery", () => {
|
||||
it("generates the registry", () => {
|
||||
const iconPack = processIconPack(buildNote({
|
||||
type: "text",
|
||||
content: JSON.stringify(manifest),
|
||||
attachments: [ defaultAttachment ]
|
||||
}));
|
||||
const registry = generateIconRegistry([ iconPack! ]);
|
||||
expect(registry.sources).toHaveLength(1);
|
||||
expect(registry.sources[0]).toMatchObject({
|
||||
name: "Boxicons v2",
|
||||
prefix: "bx",
|
||||
icons: [
|
||||
{
|
||||
id: "bx-ball",
|
||||
label: "ball"
|
||||
},
|
||||
{
|
||||
id: "bxs-party",
|
||||
label: "party"
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { IconRegistry } from "@triliumnext/commons";
|
||||
|
||||
import type BAttachment from "../becca/entities/battachment";
|
||||
import type BNote from "../becca/entities/bnote";
|
||||
import log from "./log";
|
||||
@@ -33,6 +35,23 @@ export function getIconPacks() {
|
||||
.filter(Boolean) as ProcessResult[];
|
||||
}
|
||||
|
||||
export function generateIconRegistry(iconPacks: ProcessResult[]): IconRegistry {
|
||||
const sources: IconRegistry["sources"] = [];
|
||||
|
||||
for (const { manifest } of iconPacks) {
|
||||
sources.push({
|
||||
prefix: manifest.prefix,
|
||||
name: manifest.name,
|
||||
icons: Object.keys(manifest.icons).map(id => ({
|
||||
id,
|
||||
label: id.split("-").at(-1) ?? id
|
||||
}))
|
||||
});
|
||||
}
|
||||
|
||||
return { sources };
|
||||
}
|
||||
|
||||
export function processIconPack(iconPackNote: BNote): ProcessResult | undefined {
|
||||
const manifest = iconPackNote.getJsonContentSafely() as IconPackManifest;
|
||||
if (!manifest) {
|
||||
|
||||
@@ -285,3 +285,14 @@ export interface RenderMarkdownResponse {
|
||||
export interface ToMarkdownResponse {
|
||||
markdownContent: string;
|
||||
}
|
||||
|
||||
export interface IconRegistry {
|
||||
sources: {
|
||||
prefix: string;
|
||||
name: string;
|
||||
icons: {
|
||||
id: string;
|
||||
label: string;
|
||||
}[]
|
||||
}[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user