Skip to content

Commit fc25c92

Browse files
committed
一些配置
1 parent 4aeb781 commit fc25c92

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

components/ExternalPlugins.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const ExternalPlugin = props => {
101101
// 异步渲染谷歌广告
102102
if (ADSENSE_GOOGLE_ID) {
103103
setTimeout(() => {
104-
initGoogleAdsense()
104+
initGoogleAdsense(ADSENSE_GOOGLE_ID)
105105
}, 1000)
106106
}
107107

components/GoogleAdsense.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ function getNodesWithAdsByGoogleClass(node) {
6161
* 初始化谷歌广告
6262
* @returns
6363
*/
64-
export const initGoogleAdsense = async () => {
64+
export const initGoogleAdsense = async ADSENSE_GOOGLE_ID => {
6565
console.log('Load Adsense')
6666
loadExternalResource(
67-
`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${siteConfig('ADSENSE_GOOGLE_ID')}`,
67+
`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${ADSENSE_GOOGLE_ID}`,
6868
'js'
6969
).then(url => {
7070
setTimeout(() => {
@@ -109,7 +109,9 @@ export const initGoogleAdsense = async () => {
109109
* 添加 可以在本地调试
110110
*/
111111
const AdSlot = ({ type = 'show' }) => {
112-
if (!siteConfig('ADSENSE_GOOGLE_ID')) {
112+
const ADSENSE_GOOGLE_ID = siteConfig('ADSENSE_GOOGLE_ID')
113+
const ADSENSE_GOOGLE_TEST = siteConfig('ADSENSE_GOOGLE_TEST')
114+
if (!ADSENSE_GOOGLE_ID) {
113115
return null
114116
}
115117
// 文章内嵌广告
@@ -120,8 +122,8 @@ const AdSlot = ({ type = 'show' }) => {
120122
style={{ display: 'block', textAlign: 'center' }}
121123
data-ad-layout='in-article'
122124
data-ad-format='fluid'
123-
data-adtest={siteConfig('ADSENSE_GOOGLE_TEST') ? 'on' : 'off'}
124-
data-ad-client={siteConfig('ADSENSE_GOOGLE_ID')}
125+
data-adtest={ADSENSE_GOOGLE_TEST ? 'on' : 'off'}
126+
data-ad-client={ADSENSE_GOOGLE_ID}
125127
data-ad-slot={siteConfig('ADSENSE_GOOGLE_SLOT_IN_ARTICLE')}></ins>
126128
)
127129
}
@@ -134,8 +136,8 @@ const AdSlot = ({ type = 'show' }) => {
134136
data-ad-format='fluid'
135137
data-ad-layout-key='-5j+cz+30-f7+bf'
136138
style={{ display: 'block' }}
137-
data-adtest={siteConfig('ADSENSE_GOOGLE_TEST') ? 'on' : 'off'}
138-
data-ad-client={siteConfig('ADSENSE_GOOGLE_ID')}
139+
data-adtest={ADSENSE_GOOGLE_TEST ? 'on' : 'off'}
140+
data-ad-client={ADSENSE_GOOGLE_ID}
139141
data-ad-slot={siteConfig('ADSENSE_GOOGLE_SLOT_FLOW')}></ins>
140142
)
141143
}
@@ -147,8 +149,8 @@ const AdSlot = ({ type = 'show' }) => {
147149
className='adsbygoogle'
148150
style={{ display: 'block', textAlign: 'center' }}
149151
data-ad-format='autorelaxed'
150-
data-adtest={siteConfig('ADSENSE_GOOGLE_TEST') ? 'on' : 'off'}
151-
data-ad-client={siteConfig('ADSENSE_GOOGLE_ID')}
152+
data-adtest={ADSENSE_GOOGLE_TEST ? 'on' : 'off'}
153+
data-ad-client={ADSENSE_GOOGLE_ID}
152154
data-ad-slot={siteConfig('ADSENSE_GOOGLE_SLOT_NATIVE')}></ins>
153155
)
154156
}
@@ -158,8 +160,8 @@ const AdSlot = ({ type = 'show' }) => {
158160
<ins
159161
className='adsbygoogle'
160162
style={{ display: 'block' }}
161-
data-ad-client={siteConfig('ADSENSE_GOOGLE_ID')}
162-
data-adtest={siteConfig('ADSENSE_GOOGLE_TEST') ? 'on' : 'off'}
163+
data-ad-client={ADSENSE_GOOGLE_ID}
164+
data-adtest={ADSENSE_GOOGLE_TEST ? 'on' : 'off'}
163165
data-ad-slot={siteConfig('ADSENSE_GOOGLE_SLOT_AUTO')}
164166
data-ad-format='auto'
165167
data-full-width-responsive='true'></ins>

lib/config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export const siteConfig = (key, defaultVal = null, extendConfig = {}) => {
4444
// eslint-disable-next-line react-hooks/rules-of-hooks
4545
// global = useGlobal()
4646
} catch (error) {
47-
console.warn('SiteConfig警告', key, error)
47+
// 本地调试用
48+
// console.warn('SiteConfig警告', key, error)
4849
}
4950

5051
// 首先 配置最优先读取NOTION中的表格配置

0 commit comments

Comments
 (0)