-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdx-components.tsx
72 lines (66 loc) · 2.17 KB
/
mdx-components.tsx
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
import Image, { type ImageProps } from "next/image";
import { Code } from "bright";
import { Tweet } from "react-tweet";
import { Aside } from "@/components/mdx/aside";
import { BasicDiv } from "@/components/mdx/basic-div";
import { Blockquote } from "@/components/mdx/blockquote";
import { BlockquoteWithLink } from "@/components/mdx/blockquote-with-link";
import { CodeblockTitle } from "@/components/mdx/codeblock-title";
import { H2WithAnchor } from "@/components/mdx/h2-with-anchor";
import { InlineCodeBlock } from "@/components/mdx/inline-code-block";
import { PublishedOnOldBlog } from "@/components/mdx/published-on-old-blog";
import { PublishedOnReleaseBlog } from "@/components/mdx/published-on-release-blog";
import type { MDXComponents } from "mdx/types";
Code.theme = {
dark: "solarized-dark",
light: "solarized-light",
lightSelector: "html.light",
};
export const mdxComponents: MDXComponents = {
PublishedOnOldBlog: PublishedOnOldBlog,
PublishedOnReleaseBlog: PublishedOnReleaseBlog,
Aside: Aside,
BasicDiv: BasicDiv,
BlockquoteWithLink: BlockquoteWithLink,
pre: Code,
code: ({ children }) => <InlineCodeBlock>{children}</InlineCodeBlock>,
div: ({ className, children, ...props }) => {
if (className?.includes("rehype-code-title")) {
return <CodeblockTitle {...props}>{children}</CodeblockTitle>;
}
return (
<div className={className} {...props}>
{children}
</div>
);
},
h2: ({ id, children }) => <H2WithAnchor id={id}>{children}</H2WithAnchor>,
a: ({ href, children }) => (
<a href={href} target="_blank" rel="noreferrer">
{children}
</a>
),
blockquote: ({ children }) => <Blockquote>{children}</Blockquote>,
img: (props) => (
<Image
sizes="100vw"
style={{ width: "100%", height: "auto" }}
width={450}
height={450}
placeholder="blur"
blurDataURL={"@/public/post_images/1x1-fafaf07f.png"}
{...(props as ImageProps)}
/>
),
Tweet: (props) => (
<div className="not-prose">
<Tweet {...props} />
</div>
),
};
export function useMDXComponents(components: MDXComponents): MDXComponents {
return {
...components,
...mdxComponents,
};
}