Skip to content

Commit 6727027

Browse files
committed
chore: LinkHandler 분리
1 parent c14b688 commit 6727027

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as React from "react";
2+
import { Link } from "react-router-dom";
3+
4+
const EXTERNAL_PROTOCOLS = ["http://", "https://", "mailto:", "tel:"];
5+
6+
export const LinkHandler: React.FC<React.PropsWithChildren<{ href: string }>> = ({ href, ...props }) => {
7+
// If the href starts with "http" or "https", it's an external link
8+
if (EXTERNAL_PROTOCOLS.some((protocol) => href.startsWith(protocol)))
9+
return <a href={href} target="_blank" rel="noopener noreferrer" {...props} />;
10+
11+
return <Link to={href} {...props} />;
12+
};

packages/common/src/components/mdx.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import type { MDXComponents } from "mdx/types";
1515
import muiComponents from "mui-mdx-components";
1616
import * as React from "react";
1717
import * as runtime from "react/jsx-runtime";
18-
import { Link } from "react-router-dom";
1918
import remarkGfm from "remark-gfm";
2019
import * as R from "remeda";
2120

2221
import Hooks from "../hooks";
2322
import { ErrorFallback } from "./error_handler";
23+
import { LinkHandler } from "./link_handler";
2424
import { rtrim } from "../utils/string";
2525
import { StyledDivider } from "./mdx_components/styled_divider";
2626
import { SubContentContainer } from "./mdx_components/sub_content_container";
@@ -47,16 +47,6 @@ const REGISTERED_KEYWORDS = [
4747
"}",
4848
];
4949

50-
const EXTERNAL_PROTOCOLS = ["http://", "https://", "mailto:", "tel:"];
51-
52-
const LinkHandler: React.FC<{ href: string }> = ({ href, ...props }) => {
53-
// If the href starts with "http" or "https", it's an external link
54-
if (EXTERNAL_PROTOCOLS.some((protocol) => href.startsWith(protocol)))
55-
return <a href={href} target="_blank" rel="noopener noreferrer" {...props} />;
56-
57-
return <Link to={href} {...props} />;
58-
};
59-
6050
const CustomMDXComponents: MDXComponents = {
6151
h1: (props) => <h1 style={{ margin: 0 }} {...props} />,
6252
h2: (props) => <h2 style={{ margin: 0 }} {...props} />,

0 commit comments

Comments
 (0)