From 7c34a6178a924baeeb412c3ecaa9072077bef3e2 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 2 Feb 2025 15:34:44 +0200 Subject: [PATCH] feat(in-app-help): render documentation --- src/public/app/widgets/type_widgets/doc.ts | 3 ++- src/services/in_app_help.ts | 25 +++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/public/app/widgets/type_widgets/doc.ts b/src/public/app/widgets/type_widgets/doc.ts index 433abccda..431af3d3b 100644 --- a/src/public/app/widgets/type_widgets/doc.ts +++ b/src/public/app/widgets/type_widgets/doc.ts @@ -39,7 +39,8 @@ export default class DocTypeWidget extends TypeWidget { if (docName) { // find doc based on language const lng = i18next.language; - this.$content.load(`${window.glob.appPath}/doc_notes/${lng}/${docName}.html`, (response, status) => { + const url = `${window.glob.appPath}/doc_notes/${lng}/${docName}.html`.replaceAll(" ", "%20"); + this.$content.load(url, (response, status) => { // fallback to english doc if no translation available if (status === "error") { this.$content.load(`${window.glob.appPath}/doc_notes/en/${docName}.html`); diff --git a/src/services/in_app_help.ts b/src/services/in_app_help.ts index 2991d0dc0..803fb57dd 100644 --- a/src/services/in_app_help.ts +++ b/src/services/in_app_help.ts @@ -26,21 +26,36 @@ function parseNoteMetaFile(noteMetaFile: NoteMetaFile): HiddenSubtreeItem[] { return []; } - const metaRoot = parseNoteMeta(noteMetaFile.files[0]); - return metaRoot.children ?? []; + const metaRoot = noteMetaFile.files[0]; + const parsedMetaRoot = parseNoteMeta(metaRoot, "/" + (metaRoot.dirFileName ?? "")); + console.log(JSON.stringify(parsedMetaRoot, null, 4)); + return parsedMetaRoot.children ?? []; } -function parseNoteMeta(noteMeta: NoteMeta): HiddenSubtreeItem { +function parseNoteMeta(noteMeta: NoteMeta, docNameRoot: string): HiddenSubtreeItem { const item: HiddenSubtreeItem = { id: `_help_${noteMeta.noteId}`, title: noteMeta.title, - type: "doc" + type: "doc", + attributes: [] }; + // Handle text notes + if (noteMeta.type === "text" && noteMeta.dataFileName) { + const docPath = `${docNameRoot}/${path.basename(noteMeta.dataFileName, ".html")}` + .substring(1); + item.attributes?.push({ + type: "label", + name: "docName", + value: docPath + }); + } + if (noteMeta.children) { const children: HiddenSubtreeItem[] = []; for (const childMeta of noteMeta.children) { - children.push(parseNoteMeta(childMeta)); + let newDocNameRoot = (noteMeta.dirFileName ? `${docNameRoot}/${noteMeta.dirFileName}` : docNameRoot); + children.push(parseNoteMeta(childMeta, newDocNameRoot)); } item.children = children;