Skip to content

Commit 5412d42

Browse files
committed
fix #7859 -- fix bug with relative links between static rendered markdown documents
1 parent 0c5f515 commit 5412d42

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/packages/frontend/components/smart-anchor-tag.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ import { file_associations } from "@cocalc/frontend/file-associations";
2020
import { isCoCalcURL, parseCoCalcURL } from "@cocalc/frontend/lib/cocalc-urls";
2121
import Fragment, { FragmentId } from "@cocalc/frontend/misc/fragment-id";
2222
import { ProjectTitle } from "@cocalc/frontend/projects/project-title";
23-
import { filename_extension, path_split } from "@cocalc/util/misc";
23+
import {
24+
containingPath,
25+
filename_extension,
26+
path_split,
27+
} from "@cocalc/util/misc";
2428
import { TITLE as SERVERS_TITLE } from "../project/servers";
2529
import { alert_message } from "@cocalc/frontend/alerts";
2630

@@ -345,7 +349,8 @@ function InternalRelativeLink({ project_id, path, href, title, children }) {
345349
onClick={(e) => {
346350
e.preventDefault();
347351
e.stopPropagation();
348-
const url = new URL("http://dummy/" + href);
352+
const dir = containingPath(path);
353+
const url = new URL("http://dummy/" + join(dir, href));
349354
const fragmentId = Fragment.decode(url.hash);
350355
const hrefPlain = url.pathname.slice(1);
351356
let target;
@@ -355,11 +360,7 @@ function InternalRelativeLink({ project_id, path, href, title, children }) {
355360
} else {
356361
// different file in the same project, with link being relative
357362
// to current path.
358-
target = join(
359-
"files",
360-
path ? path_split(path).head : "",
361-
decodeURI(hrefPlain),
362-
);
363+
target = join("files", decodeURI(hrefPlain));
363364
}
364365
loadTarget(
365366
"projects",

0 commit comments

Comments
 (0)