Skip to content

Commit

Permalink
Add external links for certain global identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
weareoutman committed Oct 15, 2024
1 parent 5226f4d commit 4aa6919
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/components/GeneralType/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { createContext, useContext } from "react";
import { Annotation } from "@next-core/brick-manifest";
import clsx from "clsx";
import Link from "@docusaurus/Link";
import IconExternalLink from "@theme/Icon/ExternalLink";
import styles from "./styles.module.css";

export interface GeneralTypeProps {
Expand All @@ -13,6 +15,13 @@ export const TypeReferencesContext = createContext<string[] | undefined>(
undefined
);

const ExternalLinks = new Map<string, string>([
[
"RequestInit",
"https://developer.mozilla.org/zh-CN/docs/Web/API/RequestInit",
],
]);

export default function GeneralType({
annotation,
signaturePart,
Expand Down Expand Up @@ -40,11 +49,19 @@ export default function GeneralType({
);

case "identifier": {
const hasLink = typeReferences?.includes(annotation.name);
const hasRef = typeReferences?.includes(annotation.name);
const link = hasRef
? `#ref-${annotation.name}`
: ExternalLinks.get(annotation.name);
return (
<>
{hasLink ? (
<a href={`#ref-${annotation.name}`}>{annotation.name}</a>
{hasRef ? (
<Link href={link}>{annotation.name}</Link>
) : link ? (
<Link href={link} target="_blank">
{annotation.name}
<IconExternalLink width={12} height={12} />
</Link>
) : annotation.annotation ? (
<>
{annotation.name}
Expand Down

0 comments on commit 4aa6919

Please sign in to comment.