From 659fd7e2c99026fbce7ee520828007f3815ea245 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Mon, 6 Feb 2023 17:32:38 +0000 Subject: [PATCH] feat: support img no-optimization option --- src/components/ui/Image.tsx | 21 ++++++++++++++++++++- src/markdown/sanitize-schema.ts | 8 ++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/components/ui/Image.tsx b/src/components/ui/Image.tsx index 7fe17649..e7204dfa 100644 --- a/src/components/ui/Image.tsx +++ b/src/components/ui/Image.tsx @@ -18,8 +18,27 @@ export const Image: React.FC< const [paddingTop, setPaddingTop] = React.useState("0") const [autoWidth, setAutoWidth] = React.useState(0) const autoSize = !width && !height && !fill + const noOptimization = className?.includes("no-optimization") - return ( + return noOptimization ? ( + // eslint-disable-next-line @next/next/no-img-element + {alt} { + if (autoSize) { + const { naturalWidth, naturalHeight } = target as HTMLImageElement + setPaddingTop(`calc(100% / (${naturalWidth} / ${naturalHeight})`) + setAutoWidth(naturalWidth) + } + }} + ref={imageRef} + /> + ) : (