From 94890d8e56d2a3ba5e7a7053b641d4e0b01de680 Mon Sep 17 00:00:00 2001 From: SugarMGP <2350745751@qq.com> Date: Sun, 31 May 2026 20:04:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E5=B0=81=E9=9D=A2=E5=9B=BE=E8=A2=AB=E5=BC=BA=E5=88=B6=E8=A3=81?= =?UTF-8?q?=E5=88=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/common/CoverImage.astro | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/components/common/CoverImage.astro b/src/components/common/CoverImage.astro index 8b43aa090e..2f41fa61b4 100644 --- a/src/components/common/CoverImage.astro +++ b/src/components/common/CoverImage.astro @@ -114,6 +114,14 @@ const sizes = preview : "(max-width: 768px) 100vw, (max-width: 1200px) 90vw, 1200px"; const quality = preview ? Math.round(configQuality * 0.9) : configQuality; +const getPictureSizeProps = (image: ImageMetadata) => { + if (preview) { + return { width: 400, height: 300, widths, sizes }; + } + const baseHeight = Math.round(1200 / (image.width / image.height)); + return { width: 1200, height: baseHeight, widths, sizes }; +}; + // 是否显示加载动画 const showLoading = coverImageConfig.randomCoverImage.showLoading ?? true; @@ -159,15 +167,12 @@ const remoteReferrerPolicy = alt="Fallback cover" class={imageClass} style={imageStyle} - width={preview ? 400 : 1200} - height={preview ? 300 : 800} loading="lazy" formats={formats} fallbackFormat={fallbackFormat} quality={quality} - widths={widths} - sizes={sizes} layout={layout} + {...getPictureSizeProps(fallbackImg)} /> )} @@ -192,15 +197,12 @@ const remoteReferrerPolicy = alt={alt || ""} class={imageClass} style={imageStyle} - width={preview ? 400 : 1200} - height={preview ? 300 : 800} loading={loading} formats={formats} fallbackFormat={fallbackFormat} quality={quality} - widths={widths} - sizes={sizes} layout={layout} + {...getPictureSizeProps(img)} data-cover-img /> )}