From 97bc103e7656d270fdd141efef40c43310751579 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 22 Feb 2025 12:30:35 +0200 Subject: [PATCH] feat(in_app_help): support folder icons --- src/services/in_app_help.spec.ts | 41 ++++++++++++++++++++++++++++++++ src/services/in_app_help.ts | 14 +++++------ src/services/meta/note_meta.ts | 2 +- 3 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 src/services/in_app_help.spec.ts diff --git a/src/services/in_app_help.spec.ts b/src/services/in_app_help.spec.ts new file mode 100644 index 000000000..7222b9219 --- /dev/null +++ b/src/services/in_app_help.spec.ts @@ -0,0 +1,41 @@ +import { describe, expect, expectTypeOf, it } from "vitest"; +import { parseNoteMeta } from "./in_app_help.js"; +import type NoteMeta from "./meta/note_meta.js"; + +describe("In-app help", () => { + + it("preserves custom folder icon", () => { + const meta: NoteMeta = { + "isClone": false, + "noteId": "yoAe4jV2yzbd", + "notePath": [ + "OkOZllzB3fqN", + "yoAe4jV2yzbd" + ], + "title": "Features", + "notePosition": 40, + "prefix": null, + "isExpanded": false, + "type": "text", + "mime": "text/html", + "attributes": [ + { + "type": "label", + "name": "iconClass", + "value": "bx bx-star", + "isInheritable": false, + "position": 10 + } + ], + "format": "html", + "attachments": [], + "dirFileName": "Features", + "children": [] + }; + + const item = parseNoteMeta(meta, "/"); + const icon = item.attributes?.find((a) => a.name === "iconClass"); + expect(icon?.value).toBe("bx bx-star"); + }); + +}); diff --git a/src/services/in_app_help.ts b/src/services/in_app_help.ts index a090993c4..b337f1add 100644 --- a/src/services/in_app_help.ts +++ b/src/services/in_app_help.ts @@ -33,7 +33,7 @@ function parseNoteMetaFile(noteMetaFile: NoteMetaFile): HiddenSubtreeItem[] { return parsedMetaRoot.children ?? []; } -function parseNoteMeta(noteMeta: NoteMeta, docNameRoot: string): HiddenSubtreeItem { +export function parseNoteMeta(noteMeta: NoteMeta, docNameRoot: string): HiddenSubtreeItem { let iconClass: string = "bx bx-file"; const item: HiddenSubtreeItem = { id: `_help_${noteMeta.noteId}`, @@ -42,6 +42,12 @@ function parseNoteMeta(noteMeta: NoteMeta, docNameRoot: string): HiddenSubtreeIt attributes: [] }; + // Handle folder notes + if (!noteMeta.dataFileName) { + iconClass = "bx bx-folder"; + item.type = "book"; + } + // Handle attributes for (const attribute of noteMeta.attributes ?? []) { if (attribute.name === "iconClass") { @@ -58,12 +64,6 @@ function parseNoteMeta(noteMeta: NoteMeta, docNameRoot: string): HiddenSubtreeIt } } - // Handle folder notes - if (!noteMeta.dataFileName) { - iconClass = "bx bx-folder"; - item.type = "book"; - } - // Handle text notes if (noteMeta.type === "text" && noteMeta.dataFileName) { const docPath = `${docNameRoot}/${path.basename(noteMeta.dataFileName, ".html")}` diff --git a/src/services/meta/note_meta.ts b/src/services/meta/note_meta.ts index 681ca4f8c..da908a328 100644 --- a/src/services/meta/note_meta.ts +++ b/src/services/meta/note_meta.ts @@ -20,7 +20,7 @@ export default interface NoteMeta { mime?: string; /** 'html' or 'markdown', applicable to text notes only */ format?: "html" | "markdown"; - dataFileName: string; + dataFileName?: string; dirFileName?: string; /** this file should not be imported (e.g., HTML navigation) */ noImport?: boolean;