From d901a0f787cf087958f873c42fcdad33ca2887fe Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 2 Feb 2025 19:21:36 +0200 Subject: [PATCH] fix(in-app-help): style error when loading a note --- src/public/app/widgets/type_widgets/doc.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/public/app/widgets/type_widgets/doc.ts b/src/public/app/widgets/type_widgets/doc.ts index 3dfc473a1..d9e022cb7 100644 --- a/src/public/app/widgets/type_widgets/doc.ts +++ b/src/public/app/widgets/type_widgets/doc.ts @@ -41,16 +41,15 @@ export default class DocTypeWidget extends TypeWidget { #loadContent(note: FNote) { return new Promise((resolve) => { - const docName = note.getLabelValue("docName"); + let docName = note.getLabelValue("docName"); if (docName) { // find doc based on language - const lng = i18next.language; - const url = `${window.glob.appPath}/doc_notes/${lng}/${docName}.html`.replaceAll(" ", "%20"); + const url = this.#getUrl(docName, i18next.language); this.$content.load(url, (response, status) => { // fallback to english doc if no translation available if (status === "error") { - const fallbackUrl = `${window.glob.appPath}/doc_notes/en/${docName}.html`; + const fallbackUrl = this.#getUrl(docName, "en"); this.$content.load(fallbackUrl, () => this.#processContent(fallbackUrl)); resolve(); return; @@ -65,6 +64,19 @@ export default class DocTypeWidget extends TypeWidget { }); } + #getUrl(docNameValue: string, language: string) { + // For help notes, we only get the content to avoid loading of styles and meta. + let suffix = ""; + if (docNameValue?.startsWith("User Guide")) { + suffix = " .content"; + } + + // Cannot have spaces in the URL due to how JQuery.load works. + docNameValue = docNameValue.replaceAll(" ", "%20"); + + return `${window.glob.appPath}/doc_notes/${language}/${docNameValue}.html${suffix}`; + } + #processContent(url: string) { const dir = url.substring(0, url.lastIndexOf("/"));