From 2e87f0bfe2b575d2faaee490321bf108fa4b3a9f Mon Sep 17 00:00:00 2001 From: DIYgod Date: Tue, 27 Sep 2022 01:29:10 +0100 Subject: [PATCH] feat: use nextjs image for all domains --- next.config.js | 3 +- src/components/site/PostFooter.tsx | 8 ++-- src/components/site/SiteHome.tsx | 2 + src/components/ui/Image.tsx | 66 +++++++++++------------------- 4 files changed, 33 insertions(+), 46 deletions(-) diff --git a/next.config.js b/next.config.js index c7c69dc6..b1404c3b 100644 --- a/next.config.js +++ b/next.config.js @@ -47,7 +47,8 @@ module.exports = withBundleAnalyzer( images: { dangerouslyAllowSVG: true, - domains: ["4everland.xyz"], + contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;", + remotePatterns: [{ hostname: "**" }], }, }), ) diff --git a/src/components/site/PostFooter.tsx b/src/components/site/PostFooter.tsx index b6eb87cd..c720c59c 100644 --- a/src/components/site/PostFooter.tsx +++ b/src/components/site/PostFooter.tsx @@ -229,7 +229,7 @@ export const PostFooter: React.FC<{ ?.map((like: any, index) => (
  • 3 && (
  • -
    +
    +{likes.data!.count - 3}
  • @@ -272,7 +272,7 @@ export const PostFooter: React.FC<{ .map((mint: any, index) => (
  • 3 && (
  • -
    +
    +{mints.data!.count - 3}
  • diff --git a/src/components/site/SiteHome.tsx b/src/components/site/SiteHome.tsx index 0352faf7..dab6c7d7 100644 --- a/src/components/site/SiteHome.tsx +++ b/src/components/site/SiteHome.tsx @@ -63,6 +63,8 @@ export const SiteHome: React.FC<{ className="object-cover rounded w-24 h-24" alt="cover" layout="fill" + width={96} + height={96} src={post.cover} > diff --git a/src/components/ui/Image.tsx b/src/components/ui/Image.tsx index 6a6eb07c..e283dd93 100644 --- a/src/components/ui/Image.tsx +++ b/src/components/ui/Image.tsx @@ -15,49 +15,33 @@ export const Image: React.FC< > = ({ layout, className, alt, src, width, height, ...props }) => { src = toIPFS(src) const [paddingTop, setPaddingTop] = React.useState("0") + const autoSize = !width && !width && !layout return ( - <> - {isIpfsUrl(src) ? ( - - { - if (!width && !width && !layout) { - const { naturalWidth, naturalHeight } = - target as HTMLImageElement - setPaddingTop( - `calc(100% / (${naturalWidth} / ${naturalHeight})`, - ) - } - }} - /> - - ) : ( - // eslint-disable-next-line @next/next/no-img-element - {alt} + + style={autoSize ? { paddingTop } : {}} + > + { + if (autoSize) { + const { naturalWidth, naturalHeight } = target as HTMLImageElement + setPaddingTop(`calc(100% / (${naturalWidth} / ${naturalHeight})`) + } + }} + /> + ) }