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