From 34398712d1886347150c97d4332fdb103e8db80f Mon Sep 17 00:00:00 2001 From: lisicheng Date: Mon, 16 Dec 2024 15:31:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9B=BE=E7=89=87=E7=9B=B8?= =?UTF-8?q?=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArticleList/components/ArticleCardCover.jsx | 3 +++ src/components/ArticleView/components/ArticleImage.jsx | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/ArticleList/components/ArticleCardCover.jsx b/src/components/ArticleList/components/ArticleCardCover.jsx index 0fb3d44..1685fd3 100644 --- a/src/components/ArticleList/components/ArticleCardCover.jsx +++ b/src/components/ArticleList/components/ArticleCardCover.jsx @@ -1,12 +1,14 @@ import { useEffect, useRef, useState } from "react"; import { Image } from "@nextui-org/react"; import { cn } from "@/lib/utils.js"; +import { getReferrerPolicy } from "@/lib/utils"; export default function ArticleCardCover({ imageUrl }) { const [error, setError] = useState(false); const [isVisible, setIsVisible] = useState(false); const [loading, setLoading] = useState(true); const imgRef = useRef(null); + const referrerPolicy = getReferrerPolicy(imageUrl); useEffect(() => { const imgElement = imgRef.current; @@ -68,6 +70,7 @@ export default function ArticleCardCover({ imageUrl }) { onError={() => setError(true)} radius="none" loading="lazy" + referrerPolicy={referrerPolicy} removeWrapper classNames={{ img: "object-cover w-full aspect-video", diff --git a/src/components/ArticleView/components/ArticleImage.jsx b/src/components/ArticleView/components/ArticleImage.jsx index e4c2a88..3977908 100644 --- a/src/components/ArticleView/components/ArticleImage.jsx +++ b/src/components/ArticleView/components/ArticleImage.jsx @@ -10,6 +10,8 @@ export default function ArticleImage({ imgNode }) { const { src, alt = "" } = imgNode.attribs; + const referrerPolicy = getReferrerPolicy(src); + const handleImageClick = (e) => { e.preventDefault(); @@ -48,8 +50,8 @@ export default function ArticleImage({ imgNode }) { if (error) { return ( -
-
+
+
图片加载失败
@@ -69,7 +71,7 @@ export default function ArticleImage({ imgNode }) { src={src} alt={alt} loading="lazy" - referrerPolicy={getReferrerPolicy(src)} + referrerPolicy={referrerPolicy} onError={() => setError(true)} onClick={handleImageClick} />