Skip to content

Commit

Permalink
dev: aware path to root in cross link jump
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin committed Dec 14, 2023
1 parent 4dedb52 commit 2900ef2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions frontend/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
1 change: 1 addition & 0 deletions themes/mdbook/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
<!-- Provide site root to javascript -->
<script>
var path_to_root = "{{ path_to_root }}";
window.typstPathToRoot = path_to_root;
var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "{{ preferred_dark_theme }}" : "{{ default_theme }}";
</script>

Expand Down

0 comments on commit 2900ef2

Please sign in to comment.