mirror of
https://github.com/zadam/trilium.git
synced 2026-01-03 21:24:24 +01:00
feat(icon_pack): generate icon registry for client
This commit is contained in:
parent
e346963e76
commit
e2f6f8a4e4
@ -19,6 +19,7 @@
|
|||||||
platform: "<%= platform %>",
|
platform: "<%= platform %>",
|
||||||
hasNativeTitleBar: <%= hasNativeTitleBar %>,
|
hasNativeTitleBar: <%= hasNativeTitleBar %>,
|
||||||
TRILIUM_SAFE_MODE: <%= !!process.env.TRILIUM_SAFE_MODE %>,
|
TRILIUM_SAFE_MODE: <%= !!process.env.TRILIUM_SAFE_MODE %>,
|
||||||
isRtl: <%= !!currentLocale.rtl %>
|
isRtl: <%= !!currentLocale.rtl %>,
|
||||||
|
iconRegistry: <%- JSON.stringify(iconRegistry) %>
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@ -7,7 +7,7 @@ import assetPath from "../services/asset_path.js";
|
|||||||
import attributeService from "../services/attributes.js";
|
import attributeService from "../services/attributes.js";
|
||||||
import config from "../services/config.js";
|
import config from "../services/config.js";
|
||||||
import { getCurrentLocale } from "../services/i18n.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 log from "../services/log.js";
|
||||||
import optionService from "../services/options.js";
|
import optionService from "../services/options.js";
|
||||||
import protectedSessionService from "../services/protected_session.js";
|
import protectedSessionService from "../services/protected_session.js";
|
||||||
@ -62,7 +62,8 @@ function index(req: Request, res: Response) {
|
|||||||
appPath,
|
appPath,
|
||||||
baseApiUrl: 'api/',
|
baseApiUrl: 'api/',
|
||||||
currentLocale: getCurrentLocale(),
|
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 { 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 = {
|
const manifest: IconPackManifest = {
|
||||||
name: "Boxicons v2",
|
name: "Boxicons v2",
|
||||||
@ -137,3 +137,29 @@ describe("CSS generation", () => {
|
|||||||
expect(css).toContain(".bx.bxs-party::before { content: '\\ec92'; }");
|
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 BAttachment from "../becca/entities/battachment";
|
||||||
import type BNote from "../becca/entities/bnote";
|
import type BNote from "../becca/entities/bnote";
|
||||||
import log from "./log";
|
import log from "./log";
|
||||||
@ -33,6 +35,23 @@ export function getIconPacks() {
|
|||||||
.filter(Boolean) as ProcessResult[];
|
.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 {
|
export function processIconPack(iconPackNote: BNote): ProcessResult | undefined {
|
||||||
const manifest = iconPackNote.getJsonContentSafely() as IconPackManifest;
|
const manifest = iconPackNote.getJsonContentSafely() as IconPackManifest;
|
||||||
if (!manifest) {
|
if (!manifest) {
|
||||||
|
|||||||
@ -285,3 +285,14 @@ export interface RenderMarkdownResponse {
|
|||||||
export interface ToMarkdownResponse {
|
export interface ToMarkdownResponse {
|
||||||
markdownContent: string;
|
markdownContent: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IconRegistry {
|
||||||
|
sources: {
|
||||||
|
prefix: string;
|
||||||
|
name: string;
|
||||||
|
icons: {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
}[]
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user