Path: blob/master/src/packages/next/components/misc/A.tsx
1450 views
/*1* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import Link from "next/link";6import { join } from "path";78import basePath from "lib/base-path";910export default function A(props: any) {11const { href } = props;12if (href == null) {13return <a {...copyWithout(props, new Set(["external"]))} />;14}15if (href.includes("://") || href.startsWith("mailto:")) {16return (17<a18{...copyWithout(props, new Set(["external"]))}19target={"_blank"}20rel={"noopener"}21/>22);23}24if (25props.external ||26href.startsWith("/projects") ||27href.startsWith("/settings")28) {29const props2 = copyWithout(props, new Set(["external"]));30if (!href.startsWith(basePath)) {31// @ts-ignore32props2.href = join(basePath, href);33}34return <a {...props2} target={"_blank"} rel={"noopener"} />;35}36return (37<Link href={href} {...copyWithout(props, new Set(["external", "href"]))} />38);39}4041function copyWithout(props, without: Set<string>) {42const props2 = {};43for (const key in props) {44if (!without.has(key)) {45props2[key] = props[key];46}47}48return props2;49}505152