From 2900ef2632425d6649e6c5f514f500bfe63c34cf Mon Sep 17 00:00:00 2001 From: Myriad-Dreamin Date: Thu, 14 Dec 2023 10:24:49 +0800 Subject: [PATCH] dev: aware path to root in cross link jump --- frontend/src/global.d.ts | 1 + frontend/src/main.ts | 5 ++++- themes/mdbook/index.hbs | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/src/global.d.ts b/frontend/src/global.d.ts index 2aa169b..d457961 100644 --- a/frontend/src/global.d.ts +++ b/frontend/src/global.d.ts @@ -2,6 +2,7 @@ import { TypstRenderer } from '@myriaddreamin/typst.ts/dist/esm/renderer'; declare global { interface Window { + typstPathToRoot: string | undefined; typstGetRelatedElements: any; handleTypstLocation: any; getTypstTheme(): string; diff --git a/frontend/src/main.ts b/frontend/src/main.ts index bc1ef48..bb4cbbb 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -74,7 +74,10 @@ function postProcessCrossLinks(appElem: HTMLDivElement) { const pathLabelUnicodes = url.searchParams.get('path-label')!; const labelUnicodes = url.searchParams.get('label'); const plb = decodeTypstUrlc(pathLabelUnicodes).replace('.typ', '.html'); - let absolutePath = new URL(plb, window.location.href).href; + let absolutePath = window.typstPathToRoot + ? new URL(window.typstPathToRoot, window.location.href).href + : window.location.href; + absolutePath = new URL(plb, absolutePath).href; if (labelUnicodes) { absolutePath += '#label-' + encodeURIComponent(decodeTypstUrlc(labelUnicodes)); } diff --git a/themes/mdbook/index.hbs b/themes/mdbook/index.hbs index ab2df7f..71b4031 100644 --- a/themes/mdbook/index.hbs +++ b/themes/mdbook/index.hbs @@ -129,6 +129,7 @@