一些配置

This commit is contained in:
tangly1024.com
2024-05-15 15:24:56 +08:00
parent 4aeb781101
commit fc25c9220e
3 changed files with 16 additions and 13 deletions

View File

@@ -101,7 +101,7 @@ const ExternalPlugin = props => {
// 异步渲染谷歌广告
if (ADSENSE_GOOGLE_ID) {
setTimeout(() => {
initGoogleAdsense()
initGoogleAdsense(ADSENSE_GOOGLE_ID)
}, 1000)
}

View File

@@ -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')}></ins>
)
}
@@ -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')}></ins>
)
}
@@ -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')}></ins>
)
}
@@ -158,8 +160,8 @@ const AdSlot = ({ type = 'show' }) => {
<ins
className='adsbygoogle'
style={{ display: 'block' }}
data-ad-client={siteConfig('ADSENSE_GOOGLE_ID')}
data-adtest={siteConfig('ADSENSE_GOOGLE_TEST') ? 'on' : 'off'}
data-ad-client={ADSENSE_GOOGLE_ID}
data-adtest={ADSENSE_GOOGLE_TEST ? 'on' : 'off'}
data-ad-slot={siteConfig('ADSENSE_GOOGLE_SLOT_AUTO')}
data-ad-format='auto'
data-full-width-responsive='true'></ins>

View File

@@ -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中的表格配置