fix(in-app-help): style error when loading a note

This commit is contained in:
Elian Doran 2025-02-02 19:21:36 +02:00
parent 3796818a78
commit d901a0f787
No known key found for this signature in database

View File

@ -41,16 +41,15 @@ export default class DocTypeWidget extends TypeWidget {
#loadContent(note: FNote) {
return new Promise<void>((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("/"));