Skip to content

Commit 9accc45

Browse files
committed
feat: use next/image for MDX images
1 parent 383a1e9 commit 9accc45

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/components/MDX/MDXComponents.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {Children, useContext, useMemo} from 'react';
1313
import * as React from 'react';
1414
import cn from 'classnames';
1515
import type {HTMLAttributes} from 'react';
16+
import NextImage from 'next/image';
1617

1718
import CodeBlock from './CodeBlock';
1819
import {CodeDiagram} from './CodeDiagram';
@@ -514,8 +515,16 @@ function YouTubeIframe(props: any) {
514515
}
515516

516517
function Image(props: any) {
517-
const {alt, ...rest} = props;
518-
return <img alt={alt} className="max-w-[calc(min(700px,100%))]" {...rest} />;
518+
const {alt, width, height, ...rest} = props;
519+
return (
520+
<NextImage
521+
alt={alt}
522+
width={width ? Number(width) : 700}
523+
height={height ? Number(height) : 400}
524+
className="max-w-[calc(min(700px,100%))] h-auto"
525+
{...rest}
526+
/>
527+
);
519528
}
520529

521530
export const MDXComponents = {

0 commit comments

Comments
 (0)