Skip to content

Commit 3172fb0

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

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

app/tag-data.json

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
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,
1411
"holiday": 1,
1512
"canada": 1,
1613
"images": 1,
17-
"markdown": 1,
18-
"code": 1,
19-
"features": 1
14+
"feature": 2,
15+
"writings": 1,
16+
"book": 1,
17+
"reflection": 1,
18+
"multi-author": 1
2019
}

components/MDXComponents.tsx

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@ const PlantUML = ({ code, dpi = 600 }: PlantUMLProps) => {
2121
setUrl(`https://www.plantuml.com/plantuml/img/${encoded}`)
2222
setSvgUrl(`https://www.plantuml.com/plantuml/svg/${encoded}`)
2323
}
24-
}, [code])
24+
}, [code, dpi])
2525

2626
if (!url) {
2727
return null
2828
}
2929

3030
return (
31-
<div
31+
<div
3232
className="plantuml-chart relative mx-auto max-w-4xl"
3333
onMouseEnter={() => setIsHovered(true)}
3434
onMouseLeave={() => setIsHovered(false)}
3535
>
36+
{/* eslint-disable-next-line @next/next/no-img-element */}
3637
<img
3738
src={url}
3839
alt="PlantUML diagram"
@@ -44,7 +45,7 @@ const PlantUML = ({ code, dpi = 600 }: PlantUMLProps) => {
4445
target="_blank"
4546
rel="noopener noreferrer"
4647
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'
48+
isHovered ? 'translate-y-0 opacity-100' : 'translate-y-2 opacity-0'
4849
}`}
4950
>
5051
View SVG

components/PreviewableCode.tsx

Lines changed: 3 additions & 3 deletions
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)