diff --git a/components/ExternalPlugins.js b/components/ExternalPlugins.js index da0b0fb3..89c18688 100644 --- a/components/ExternalPlugins.js +++ b/components/ExternalPlugins.js @@ -101,7 +101,7 @@ const ExternalPlugin = props => { // 异步渲染谷歌广告 if (ADSENSE_GOOGLE_ID) { setTimeout(() => { - initGoogleAdsense() + initGoogleAdsense(ADSENSE_GOOGLE_ID) }, 1000) } diff --git a/components/GoogleAdsense.js b/components/GoogleAdsense.js index ff9b2eec..5f17f6ae 100644 --- a/components/GoogleAdsense.js +++ b/components/GoogleAdsense.js @@ -61,10 +61,10 @@ function getNodesWithAdsByGoogleClass(node) { * 初始化谷歌广告 * @returns */ -export const initGoogleAdsense = async () => { +export const initGoogleAdsense = async ADSENSE_GOOGLE_ID => { console.log('Load Adsense') loadExternalResource( - `https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${siteConfig('ADSENSE_GOOGLE_ID')}`, + `https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${ADSENSE_GOOGLE_ID}`, 'js' ).then(url => { setTimeout(() => { @@ -109,7 +109,9 @@ export const initGoogleAdsense = async () => { * 添加 可以在本地调试 */ const AdSlot = ({ type = 'show' }) => { - if (!siteConfig('ADSENSE_GOOGLE_ID')) { + const ADSENSE_GOOGLE_ID = siteConfig('ADSENSE_GOOGLE_ID') + const ADSENSE_GOOGLE_TEST = siteConfig('ADSENSE_GOOGLE_TEST') + if (!ADSENSE_GOOGLE_ID) { return null } // 文章内嵌广告 @@ -120,8 +122,8 @@ const AdSlot = ({ type = 'show' }) => { style={{ display: 'block', textAlign: 'center' }} data-ad-layout='in-article' data-ad-format='fluid' - data-adtest={siteConfig('ADSENSE_GOOGLE_TEST') ? 'on' : 'off'} - data-ad-client={siteConfig('ADSENSE_GOOGLE_ID')} + data-adtest={ADSENSE_GOOGLE_TEST ? 'on' : 'off'} + data-ad-client={ADSENSE_GOOGLE_ID} data-ad-slot={siteConfig('ADSENSE_GOOGLE_SLOT_IN_ARTICLE')}> ) } @@ -134,8 +136,8 @@ const AdSlot = ({ type = 'show' }) => { data-ad-format='fluid' data-ad-layout-key='-5j+cz+30-f7+bf' style={{ display: 'block' }} - data-adtest={siteConfig('ADSENSE_GOOGLE_TEST') ? 'on' : 'off'} - data-ad-client={siteConfig('ADSENSE_GOOGLE_ID')} + data-adtest={ADSENSE_GOOGLE_TEST ? 'on' : 'off'} + data-ad-client={ADSENSE_GOOGLE_ID} data-ad-slot={siteConfig('ADSENSE_GOOGLE_SLOT_FLOW')}> ) } @@ -147,8 +149,8 @@ const AdSlot = ({ type = 'show' }) => { className='adsbygoogle' style={{ display: 'block', textAlign: 'center' }} data-ad-format='autorelaxed' - data-adtest={siteConfig('ADSENSE_GOOGLE_TEST') ? 'on' : 'off'} - data-ad-client={siteConfig('ADSENSE_GOOGLE_ID')} + data-adtest={ADSENSE_GOOGLE_TEST ? 'on' : 'off'} + data-ad-client={ADSENSE_GOOGLE_ID} data-ad-slot={siteConfig('ADSENSE_GOOGLE_SLOT_NATIVE')}> ) } @@ -158,8 +160,8 @@ const AdSlot = ({ type = 'show' }) => { diff --git a/lib/config.js b/lib/config.js index 8b27c7f1..478bf84e 100644 --- a/lib/config.js +++ b/lib/config.js @@ -44,7 +44,8 @@ export const siteConfig = (key, defaultVal = null, extendConfig = {}) => { // eslint-disable-next-line react-hooks/rules-of-hooks // global = useGlobal() } catch (error) { - console.warn('SiteConfig警告', key, error) + // 本地调试用 + // console.warn('SiteConfig警告', key, error) } // 首先 配置最优先读取NOTION中的表格配置