-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Using Next.js Image component in markdown files (#6454)
* feat: next/image added into the mdx components * refactor: Image moved into the html components * refactor: mdx image component added * refactor: static img to Image component * chore: Image loading eager to default * chore: revert image bracket
- Loading branch information
1 parent
268a4e0
commit af0f82e
Showing
3 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { ImageProps } from 'next/image'; | ||
import Image from 'next/image'; | ||
import type { FC } from 'react'; | ||
|
||
const MDXImage: FC<ImageProps> = ({ width, height, alt, ...props }) => { | ||
if (!width || !height) { | ||
// Since `width` and `height` are not provided in the Markdown image format, | ||
// we provide the height and width automatically. | ||
// @see https://nextjs.org/docs/pages/building-your-application/optimizing/images | ||
return ( | ||
<Image | ||
{...props} | ||
alt={alt} | ||
width={0} | ||
height={0} | ||
sizes="(min-width: 768px) 200vw, 500vw" | ||
className="h-auto w-auto" | ||
/> | ||
); | ||
} | ||
|
||
return <Image {...props} alt={alt} width={width} height={height} />; | ||
}; | ||
|
||
export default MDXImage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters