@@ -11,28 +11,43 @@ import LinkButton from '@/components/mdx/LinkButton';
1111import { LinkIcon } from 'lucide-react' ;
1212
1313const slugify = ( title : string | React . ReactNode [ ] ) => {
14- const toReplace = / [ \s ( ) ? ! , ] + / g;
15- if ( typeof title === 'string' ) return title . toLowerCase ( ) . replaceAll ( toReplace , '-' ) ;
16- return ( title ! [ 0 ] as string ) ! . toLowerCase ( ) . replaceAll ( toReplace , '-' ) ;
14+ const toReplace = / [ \s ( ) ? ! , ' & ] + / g;
15+ let res : string ;
16+
17+ if ( typeof title === 'string' ) {
18+ res = title . toLowerCase ( ) . replaceAll ( toReplace , '-' ) ;
19+ } else {
20+ // Only get the first part for React components
21+ res = ( title ! [ 0 ] as string ) ! . toLowerCase ( ) . replaceAll ( toReplace , '-' ) ;
22+ }
23+
24+ if ( res . endsWith ( '-' ) ) res = res . slice ( 0 , - 1 ) ;
25+ return res ;
1726} ;
1827
1928const components : MDXComponents = {
2029 h2 : ( { children } ) => (
21- < div className = "flex items-center mb-3 mt-6 gap-2 group " id = { slugify ( children ) } >
30+ < div className = "group mb-3 mt-6 flex items-center gap-2" id = { slugify ( children ) } >
2231 < h2 className = "text-2xl font-bold" > { children } </ h2 >
23- < Link href = { `#${ slugify ( children ) } ` } className = "size-5 md:opacity-0 md:group-hover:opacity-100 duration-100" > < LinkIcon /> </ Link >
32+ < Link
33+ href = { `#${ slugify ( children ) } ` } className = "size-5 duration-100 md:opacity-0 md:group-hover:opacity-100" aria-hidden
34+ > < LinkIcon /> </ Link >
2435 </ div >
2536 ) ,
2637 h3 : ( { children } ) => (
27- < div className = "flex items-center mb-3 mt-6 gap-2 group " id = { slugify ( children ) } >
38+ < div className = "group mb-3 mt-6 flex items-center gap-2" id = { slugify ( children ) } >
2839 < h3 className = "text-xl font-bold" > { children } </ h3 >
29- < Link href = { `#${ slugify ( children ) } ` } className = "size-5 md:opacity-0 md:group-hover:opacity-100 duration-100" > < LinkIcon /> </ Link >
40+ < Link
41+ href = { `#${ slugify ( children ) } ` } className = "size-5 duration-100 md:opacity-0 md:group-hover:opacity-100" aria-hidden
42+ > < LinkIcon /> </ Link >
3043 </ div >
3144 ) ,
3245 h4 : ( { children } ) => (
33- < div className = "flex items-center mb-3 mt-6 gap-2 group " id = { slugify ( children ) } >
46+ < div className = "group mb-3 mt-6 flex items-center gap-2" id = { slugify ( children ) } >
3447 < h4 className = "text-lg font-bold" > { children } </ h4 >
35- < Link href = { `#${ slugify ( children ) } ` } className = "size-5 md:opacity-0 md:group-hover:opacity-100 duration-100" > < LinkIcon /> </ Link >
48+ < Link
49+ href = { `#${ slugify ( children ) } ` } className = "size-5 duration-100 md:opacity-0 md:group-hover:opacity-100" aria-hidden
50+ > < LinkIcon /> </ Link >
3651 </ div >
3752 ) ,
3853 code : ( { children } ) => (
@@ -42,27 +57,31 @@ const components: MDXComponents = {
4257 < p className = "mt-3" > { children } </ p >
4358 ) ,
4459 ul : ( { children } ) => (
45- < ul className = "list-inside list-disc mt-2 " > { children } </ ul >
60+ < ul className = "mt-2 list-inside list-disc" > { children } </ ul >
4661 ) ,
4762 ol : ( { children } ) => (
48- < ol className = "list-inside list-decimal mt-2 " > { children } </ ol >
63+ < ol className = "mt-2 list-inside list-decimal" > { children } </ ol >
4964 ) ,
5065 img : ( props ) => (
51- < Image { ...( props as ImageProps ) } className = "size-full md:w-auto" />
66+ < a href = { props . src ?. src || props . src } target = "_blank" rel = "nofollow" >
67+ { /* The remark plugin will automatically extract the alt text from the Markdown */ }
68+ { /* eslint-disable-next-line jsx-a11y/alt-text */ }
69+ < Image { ...( props as ImageProps ) } className = "size-full rounded-xl border border-border md:w-auto" />
70+ </ a >
5271 ) ,
5372 a : ( { href, children } : { href : string , children : React . ReactNode } ) => {
5473 const isExternal = href . startsWith ( 'http' ) ;
5574 if ( ! isExternal ) {
56- return < Link href = { href } className = "text-blue-500 hover:text-blue-600 transition-colors " > { children } </ Link > ;
75+ return < Link href = { href } className = "text-blue-500 transition-colors hover:text-blue-600" > { children } </ Link > ;
5776 }
5877
5978 return < a
6079 href = { href } target = "_blank" rel = { href . startsWith ( 'https://miwa.lol/' ) ? undefined : 'noreferrer' }
61- className = "text-blue-500 hover:text-blue-600 transition-colors "
80+ className = "text-blue-500 transition-colors hover:text-blue-600"
6281 > { children } </ a > ;
6382 } ,
6483 th : ( { children } ) => < th className = "p-2 text-left" > { children } </ th > ,
65- td : ( { children } ) => < td className = "p-2 border-y border-border" > { children } </ td > ,
84+ td : ( { children } ) => < td className = "border-y border-border p-2 " > { children } </ td > ,
6685
6786 Aside,
6887 Badge,
0 commit comments