Skip to content

Commit 71c26a4

Browse files
committed
refactor: improve component structure and clean up code
1 parent 40ac98f commit 71c26a4

File tree

5 files changed

+23
-20
lines changed

5 files changed

+23
-20
lines changed

app/tag-data.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
2+
"markdown": 2,
3+
"code": 2,
4+
"features": 2,
25
"next-js": 6,
3-
"tailwind": 3,
4-
"guide": 5,
5-
"feature": 2,
6-
"multi-author": 1,
7-
"hello": 1,
86
"math": 1,
97
"ols": 1,
108
"github": 1,
11-
"writings": 1,
12-
"book": 1,
13-
"reflection": 1,
9+
"guide": 5,
10+
"tailwind": 3,
11+
"hello": 1,
1412
"holiday": 1,
1513
"canada": 1,
1614
"images": 1,
17-
"markdown": 1,
18-
"code": 1,
19-
"features": 1
15+
"feature": 2,
16+
"writings": 1,
17+
"book": 1,
18+
"reflection": 1,
19+
"multi-author": 1
2020
}

components/MDXComponents.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ export const components: MDXComponents = {
2222
pre: (props) => <PreviewableCode defaultView={'code'} renderers={renderers} {...props} />,
2323
table: TableWrapper,
2424
BlogNewsletterForm,
25-
}
25+
}

components/Mermaid.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const ErrorDisplay = ({ error, code }: ErrorDisplayProps) => (
6060
</div>
6161
</summary>
6262
<div className="border-b border-red-200 bg-red-50 px-4 py-2">
63-
<pre className="whitespace-pre-wrap break-words font-mono text-sm font-medium text-red-700">
63+
<pre className="font-mono text-sm font-medium break-words whitespace-pre-wrap text-red-700">
6464
{typeof error === 'string' ? error : error.message || 'Failed to render diagram'}
6565
</pre>
6666
</div>

components/PlantUML.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useEffect, useState } from 'react'
44
import PlantUmlEncoder from 'plantuml-encoder'
5+
import Image from 'next/image'
56

67
interface PlantUMLProps {
78
code: string
@@ -21,21 +22,23 @@ const PlantUML = ({ code, dpi = 600 }: PlantUMLProps) => {
2122
setUrl(`https://www.plantuml.com/plantuml/img/${encoded}`)
2223
setSvgUrl(`https://www.plantuml.com/plantuml/svg/${encoded}`)
2324
}
24-
}, [code])
25+
}, [code, dpi])
2526

2627
if (!url) {
2728
return null
2829
}
2930

3031
return (
31-
<div
32+
<div
3233
className="plantuml-chart relative mx-auto max-w-4xl"
3334
onMouseEnter={() => setIsHovered(true)}
3435
onMouseLeave={() => setIsHovered(false)}
3536
>
36-
<img
37+
<Image
3738
src={url}
3839
alt="PlantUML diagram"
40+
width={1200}
41+
height={800}
3942
className="mx-auto block w-full rounded-md object-contain"
4043
style={{ maxHeight: '80vh' }}
4144
/>
@@ -44,7 +47,7 @@ const PlantUML = ({ code, dpi = 600 }: PlantUMLProps) => {
4447
target="_blank"
4548
rel="noopener noreferrer"
4649
className={`absolute right-2 bottom-2 rounded-md bg-white/80 px-2 py-1 text-xs text-gray-600 shadow-sm transition-all duration-200 hover:bg-white hover:text-gray-900 dark:bg-gray-800/80 dark:text-gray-400 dark:hover:bg-gray-800 dark:hover:text-gray-200 ${
47-
isHovered ? 'opacity-100 translate-y-0' : 'opacity-0 translate-y-2'
50+
isHovered ? 'translate-y-0 opacity-100' : 'translate-y-2 opacity-0'
4851
}`}
4952
>
5053
View SVG

components/PreviewableCode.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ const isPreviewableCodeBlock = (children: unknown): children is PreviewableCodeB
2929
typeof children === 'object' &&
3030
'props' in children &&
3131
'type' in children &&
32-
(children as any).type === 'code'
32+
children.type === 'code'
3333
)
3434
}
3535

3636
interface PreviewableCodeProps {
3737
children: ReactNode
3838
enablePreview?: boolean
3939
defaultView?: 'preview' | 'code'
40-
renderers: { [key: string]: ComponentType<any> }
40+
renderers: { [key: string]: ComponentType<{ code: string; [key: string]: unknown }> }
4141
[key: string]: unknown
4242
}
4343

@@ -109,7 +109,7 @@ const PreviewableCode = ({
109109
</TabPanels>
110110
<TabPanel>
111111
<div className="">
112-
<Renderer code={rawText} {...props} />
112+
<Renderer {...props} code={rawText} />
113113
</div>
114114
</TabPanel>
115115
</TabGroup>

0 commit comments

Comments
 (0)