Skip to content

Commit e7bb9b1

Browse files
authored
Merge pull request #172 from ethereum/animated-images
Implement `unoptimized` for animated images
2 parents 39fa2e4 + 108a4c4 commit e7bb9b1

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/components/MarkdownImage.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { extname } from "path"
2+
13
import { Flex } from "@chakra-ui/react"
24

35
import { Image, type ImageProps } from "@/components/Image"
@@ -34,6 +36,9 @@ const MarkdownImage = ({
3436
imageHeight = CONTENT_IMAGES_MAX_WIDTH / imageAspectRatio
3537
}
3638

39+
const fileExt = extname(transformedSrc).toLowerCase()
40+
const isAnimated = [".gif", ".apng", ".webp"].includes(fileExt)
41+
3742
return (
3843
// display the wrapper as a `span` to avoid dom nesting warnings as mdx
3944
// sometimes wraps images in `p` tags
@@ -45,6 +50,7 @@ const MarkdownImage = ({
4550
height={imageHeight}
4651
loading="lazy"
4752
src={transformedSrc}
53+
unoptimized={isAnimated}
4854
{...rest}
4955
/>
5056
</Link>

0 commit comments

Comments
 (0)