From deefd961594427571e1ec2a15c93037902a6761b Mon Sep 17 00:00:00 2001 From: Shahriar <31452340+ShahriarKh@users.noreply.github.com> Date: Sat, 6 Jul 2024 15:14:08 +0330 Subject: [PATCH 1/2] improve url suffix handling --- src/frame.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/frame.ts b/src/frame.ts index 8a727e3..370c85d 100644 --- a/src/frame.ts +++ b/src/frame.ts @@ -2,7 +2,6 @@ import { Platform } from "obsidian"; import { CustomFrameSettings, CustomFramesSettings, getId } from "./settings"; export class CustomFrame { - private readonly settings: CustomFramesSettings; private readonly data: CustomFrameSettings; private frame: HTMLIFrameElement | any; @@ -14,8 +13,7 @@ export class CustomFrame { create(parent: HTMLElement, additionalStyle: string = undefined, urlSuffix: string = undefined): void { let style = `padding: ${this.settings.padding}px;`; - if (additionalStyle) - style += additionalStyle; + if (additionalStyle) style += additionalStyle; if (Platform.isDesktopApp && !this.data.forceIframe) { let frameDoc = parent.doc; this.frame = frameDoc.createElement("webview"); @@ -24,7 +22,7 @@ export class CustomFrame { this.frame.addEventListener("dom-ready", () => { this.frame.setZoomFactor(this.data.zoomLevel); this.frame.insertCSS(this.data.customCss); - this.frame.executeJavaScript(this.data.customJs) + this.frame.executeJavaScript(this.data.customJs); }); this.frame.addEventListener("destroyed", () => { // recreate the webview if it was moved to a new window @@ -44,13 +42,18 @@ export class CustomFrame { this.frame.addClass(`custom-frames-${getId(this.data)}`); this.frame.setAttribute("style", style); - let src = this.data.url; + let src = new URL(this.data.url); + if (urlSuffix) { - if (!urlSuffix.startsWith("/")) - src += "/"; - src += urlSuffix; + let suffix = new URL(urlSuffix, src); + suffix.searchParams.forEach((value, key) => { + src.searchParams.set(key, value); + }); + src.hash = suffix.hash || src.hash; + src.pathname += suffix.pathname; } - this.frame.setAttribute("src", src); + + this.frame.setAttribute("src", src.toString()); } refresh(): void { From 3898f04c0e65e3787d57014bf07aad5acdbec177 Mon Sep 17 00:00:00 2001 From: Shahriar <31452340+ShahriarKh@users.noreply.github.com> Date: Sat, 6 Jul 2024 15:36:17 +0330 Subject: [PATCH 2/2] fix empty nested routes --- src/frame.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/frame.ts b/src/frame.ts index 370c85d..d22245a 100644 --- a/src/frame.ts +++ b/src/frame.ts @@ -45,12 +45,17 @@ export class CustomFrame { let src = new URL(this.data.url); if (urlSuffix) { - let suffix = new URL(urlSuffix, src); + let suffix = new URL(urlSuffix, src.origin); + suffix.searchParams.forEach((value, key) => { src.searchParams.set(key, value); }); + + if (suffix.pathname !== "/") { + src.pathname += suffix.pathname; + } + src.hash = suffix.hash || src.hash; - src.pathname += suffix.pathname; } this.frame.setAttribute("src", src.toString());