From 0e4e6b278626945a9041c3ba0aed35479fa9ac36 Mon Sep 17 00:00:00 2001 From: anime Date: Tue, 3 Dec 2024 19:35:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E4=BF=AE=E5=A4=8D=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=B0=83=E7=94=A8React=20HOOK=E7=9A=84=E9=97=AE=E9=A2=98):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/GoogleAdsense.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/components/GoogleAdsense.js b/components/GoogleAdsense.js index 5f17f6ae288..f102847bf96 100644 --- a/components/GoogleAdsense.js +++ b/components/GoogleAdsense.js @@ -39,6 +39,7 @@ function requestAd(ads) { // 获取节点或其子节点中包含 adsbygoogle 类的节点 function getNodesWithAdsByGoogleClass(node) { const adsNodes = [] + // 检查节点及其子节点是否包含 adsbygoogle 类 function checkNodeForAds(node) { if ( @@ -53,6 +54,7 @@ function getNodesWithAdsByGoogleClass(node) { } } } + checkNodeForAds(node) return adsNodes } @@ -174,6 +176,9 @@ const AdSlot = ({ type = 'show' }) => { * @param {*} props */ const AdEmbed = () => { + const ADSENSE_GOOGLE_ID = siteConfig('ADSENSE_GOOGLE_ID') + const ADSENSE_GOOGLE_TEST = siteConfig('ADSENSE_GOOGLE_TEST') + const ADSENSE_GOOGLE_SLOT_AUTO = siteConfig('ADSENSE_GOOGLE_SLOT_AUTO') useEffect(() => { setTimeout(() => { // 找到所有 class 为 notion-text 且内容为 '' 的 div 元素 @@ -187,18 +192,12 @@ const AdEmbed = () => { const newInsElement = document.createElement('ins') newInsElement.className = 'adsbygoogle w-full py-1' newInsElement.style.display = 'block' - newInsElement.setAttribute( - 'data-ad-client', - siteConfig('ADSENSE_GOOGLE_ID') - ) + newInsElement.setAttribute('data-ad-client', ADSENSE_GOOGLE_ID) newInsElement.setAttribute( 'data-adtest', - siteConfig('ADSENSE_GOOGLE_TEST') ? 'on' : 'off' - ) - newInsElement.setAttribute( - 'data-ad-slot', - siteConfig('ADSENSE_GOOGLE_SLOT_AUTO') + ADSENSE_GOOGLE_TEST ? 'on' : 'off' ) + newInsElement.setAttribute('data-ad-slot', ADSENSE_GOOGLE_SLOT_AUTO) newInsElement.setAttribute('data-ad-format', 'auto') newInsElement.setAttribute('data-full-width-responsive', 'true')