-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdx-components.tsx
77 lines (76 loc) · 2.36 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
73
74
75
76
77
import type { MDXComponents } from 'mdx/types'
import { CodeBlock } from '@/components/mdx-code-block'
import { assetPrefix } from '@/lib/utils'
import { ButtonLink } from '@/components/ui/button-link'
import { BlogCarousel, BlogCarouselProps } from '@/components/blog-carousel'
// This file is required to use MDX in `app` directory.
export function MDXComponents(components: MDXComponents = {}): MDXComponents {
return {
h1: ({ children }) => (
<h1 className="scroll-m-20 text-4xl font-bold tracking-tight lg:text-5xl mb-8 mt-16">
{children}
</h1>
),
h2: ({ children }) => (
<h2 className="scroll-m-20 text-3xl font-semibold tracking-tight first:mt-0 mb-6 mt-16">
{children}
</h2>
),
h3: ({ children }) => (
<h3 className="scroll-m-20 text-2xl font-semibold tracking-tight mb-4 mt-12">
{children}
</h3>
),
p: ({ children }) => <p className="leading-7 mb-6">{children}</p>,
a: ({ children, href }) => (
<a
href={href}
className="font-medium text-indigo-400 hover:text-indigo-300 transition-colors"
>
{children}
</a>
),
ul: ({ children }) => (
<ul className="my-8 ml-6 list-disc space-y-3 marker:text-indigo-500">
{children}
</ul>
),
ol: ({ children }) => (
<ol className="my-8 ml-6 list-decimal space-y-3">{children}</ol>
),
blockquote: ({ children }) => (
<blockquote className="my-8 border-l-4 border-indigo-500 pl-6 py-3 bg-indigo-950/30 italic">
{children}
</blockquote>
),
img: ({ src, alt }) => (
<img
src={`${assetPrefix}${src}`}
alt={alt}
className="mt-8 rounded-xl shadow-xl bg-gray-800 p-2"
/>
),
pre: ({ children }) => children,
code: ({ children, className }) => {
const language = className?.replace('language-', '')
if (typeof children !== 'string') return null
return (
<CodeBlock language={language} className="my-6">
{children}
</CodeBlock>
)
},
BlogCarousel: ({ images }: BlogCarouselProps) => (
<BlogCarousel
images={images.map((image) => ({
...image,
src: `${assetPrefix}${image.src}`,
}))}
/>
),
Button: ({ children, href }) => (
<ButtonLink href={href}>{children}</ButtonLink>
),
...components,
}
}