Skip to content

Commit

Permalink
一些配置
Browse files Browse the repository at this point in the history
  • Loading branch information
tangly1024 committed May 15, 2024
1 parent 4aeb781 commit fc25c92
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion components/ExternalPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const ExternalPlugin = props => {
// 异步渲染谷歌广告
if (ADSENSE_GOOGLE_ID) {
setTimeout(() => {
initGoogleAdsense()
initGoogleAdsense(ADSENSE_GOOGLE_ID)
}, 1000)
}

Expand Down
24 changes: 13 additions & 11 deletions components/GoogleAdsense.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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
}
// 文章内嵌广告
Expand All @@ -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>
)
}
Expand All @@ -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>
)
}
Expand All @@ -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>
)
}
Expand All @@ -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>
Expand Down
3 changes: 2 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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中的表格配置
Expand Down

0 comments on commit fc25c92

Please sign in to comment.