Repository navigation
Expand file tree
/
Copy pathMDXContent.tsx
More file actions
94 lines (87 loc) · 2.4 KB
/
Copy pathMDXContent.tsx
File metadata and controls
94 lines (87 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import * as React from "react";
import { graphql, Link } from "gatsby";
import { MDXProvider } from "@mdx-js/react";
import { MDXRenderer } from "gatsby-plugin-mdx";
import Container from "@mui/material/Container";
import Box from "@mui/material/Box";
import * as MDXConponents from "components/MDXComponents";
import {
CustomNotice,
MachineTranslationNotice,
ArchiveTiDBNotice,
} from "components/Card/CustomNotice";
import { Locale, PathConfig, FrontMatter, BuildType } from "static/Type";
import { useTotalContributors } from "components/Avatar/Contributors";
import replaceInternalHref from "utils/anchor";
import { Pre } from "components/MDXComponents/Pre";
import { MdxContext } from "context/MdxContext";
export default function MDXContent(props: {
data: any;
className?: string;
name: string;
pathConfig: PathConfig;
filePath: string;
frontmatter: FrontMatter;
availIn: string[];
language: string;
buildType: BuildType;
}) {
const {
data,
className,
name,
pathConfig,
filePath,
frontmatter,
availIn,
language,
buildType,
} = props;
React.useEffect(() => {
// https://github.com/pingcap/website-docs/issues/221
// md title with html tag will cause anchor mismatch
pathConfig &&
replaceInternalHref(
pathConfig.locale,
pathConfig.repo,
pathConfig.version || ""
);
});
!frontmatter?.hide_commit && useTotalContributors(pathConfig, filePath);
return (
<Container className={className} maxWidth="xl">
<Box className="markdown-body">
{buildType === "archive" && typeof name !== "undefined" && (
<ArchiveTiDBNotice
name={name}
pathConfig={pathConfig}
availIn={availIn}
/>
)}
{buildType !== "archive" && (
<CustomNotice name={name} pathConfig={pathConfig} availIn={availIn} />
)}
{language === "ja" && (
<MachineTranslationNotice
name={name}
pathConfig={pathConfig}
availIn={availIn}
/>
)}
<MdxContext.Provider
value={{pathConfig}}
>
<MDXProvider
components={{
...MDXConponents,
Link,
pre: Pre,
}}
>
<MDXRenderer>{data}</MDXRenderer>
</MDXProvider>
</MdxContext.Provider>
</Box>
</Container>
);
}