CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/components/share/linked-path.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import Link from "next/link";
7
8
interface Props {
9
id: string;
10
path: string;
11
relativePath: string;
12
isDir?: boolean;
13
}
14
15
export default function LinkedPath({ id, path, relativePath, isDir }: Props) {
16
let href = `/share/public_paths/${id}`;
17
const first = (
18
<Link href={href} key={href}>
19
{path}
20
</Link>
21
);
22
const slash = (key) => <span key={"slash" + key}> / </span>;
23
const segments: JSX.Element[] = [first, slash(href)];
24
for (const segment of relativePath.split("/")) {
25
if (!segment) continue;
26
href += `/${encodeURIComponent(segment)}`;
27
segments.push(
28
<Link href={href} key={href}>
29
{segment}
30
</Link>
31
);
32
segments.push(slash(href));
33
}
34
if (!isDir) {
35
segments.pop();
36
}
37
return <>{segments}</>;
38
}
39
40