forked from tangly1024/NotionNext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExternalPlugins.js
446 lines (418 loc) · 14.2 KB
/
ExternalPlugins.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
import { siteConfig } from '@/lib/config'
import { convertInnerUrl } from '@/lib/notion/convertInnerUrl'
import { isBrowser, loadExternalResource } from '@/lib/utils'
import dynamic from 'next/dynamic'
import { useRouter } from 'next/router'
import { useEffect } from 'react'
import { GlobalStyle } from './GlobalStyle'
import { initGoogleAdsense } from './GoogleAdsense'
import Head from 'next/head'
import ExternalScript from './ExternalScript'
import WebWhiz from './Webwhiz'
/**
* 各种插件脚本
* @param {*} props
* @returns
*/
const ExternalPlugin = props => {
const DISABLE_PLUGIN = siteConfig('DISABLE_PLUGIN')
const THEME_SWITCH = siteConfig('THEME_SWITCH')
const DEBUG = siteConfig('DEBUG')
const ANALYTICS_ACKEE_TRACKER = siteConfig('ANALYTICS_ACKEE_TRACKER')
const ANALYTICS_VERCEL = siteConfig('ANALYTICS_VERCEL')
const ANALYTICS_BUSUANZI_ENABLE = siteConfig('ANALYTICS_BUSUANZI_ENABLE')
const ADSENSE_GOOGLE_ID = siteConfig('ADSENSE_GOOGLE_ID')
const FACEBOOK_APP_ID = siteConfig('FACEBOOK_APP_ID')
const FACEBOOK_PAGE_ID = siteConfig('FACEBOOK_PAGE_ID')
const FIREWORKS = siteConfig('FIREWORKS')
const SAKURA = siteConfig('SAKURA')
const STARRY_SKY = siteConfig('STARRY_SKY')
const MUSIC_PLAYER = siteConfig('MUSIC_PLAYER')
const NEST = siteConfig('NEST')
const FLUTTERINGRIBBON = siteConfig('FLUTTERINGRIBBON')
const COMMENT_TWIKOO_COUNT_ENABLE = siteConfig('COMMENT_TWIKOO_COUNT_ENABLE')
const RIBBON = siteConfig('RIBBON')
const CUSTOM_RIGHT_CLICK_CONTEXT_MENU = siteConfig(
'CUSTOM_RIGHT_CLICK_CONTEXT_MENU'
)
const CAN_COPY = siteConfig('CAN_COPY')
const WEB_WHIZ_ENABLED = siteConfig('WEB_WHIZ_ENABLED')
const AD_WWADS_BLOCK_DETECT = siteConfig('AD_WWADS_BLOCK_DETECT')
const CHATBASE_ID = siteConfig('CHATBASE_ID')
const COMMENT_DAO_VOICE_ID = siteConfig('COMMENT_DAO_VOICE_ID')
const AD_WWADS_ID = siteConfig('AD_WWADS_ID')
const COMMENT_ARTALK_SERVER = siteConfig('COMMENT_ARTALK_SERVER')
const COMMENT_ARTALK_JS = siteConfig('COMMENT_ARTALK_JS')
const COMMENT_TIDIO_ID = siteConfig('COMMENT_TIDIO_ID')
const COMMENT_GITTER_ROOM = siteConfig('COMMENT_GITTER_ROOM')
const ANALYTICS_BAIDU_ID = siteConfig('ANALYTICS_BAIDU_ID')
const ANALYTICS_CNZZ_ID = siteConfig('ANALYTICS_CNZZ_ID')
const ANALYTICS_GOOGLE_ID = siteConfig('ANALYTICS_GOOGLE_ID')
const MATOMO_HOST_URL = siteConfig('MATOMO_HOST_URL')
const MATOMO_SITE_ID = siteConfig('MATOMO_SITE_ID')
const ANALYTICS_51LA_ID = siteConfig('ANALYTICS_51LA_ID')
const ANALYTICS_51LA_CK = siteConfig('ANALYTICS_51LA_CK')
const DIFY_CHATBOT_ENABLED = siteConfig('DIFY_CHATBOT_ENABLED')
const TIANLI_KEY = siteConfig('TianliGPT_KEY')
const GLOBAL_JS = siteConfig('GLOBAL_JS', '')
const CLARITY_ID = siteConfig('CLARITY_ID')
const IMG_SHADOW = siteConfig('IMG_SHADOW')
const ANIMATE_CSS_URL = siteConfig('ANIMATE_CSS_URL')
const MOUSE_FOLLOW = siteConfig('MOUSE_FOLLOW')
const CUSTOM_EXTERNAL_CSS = siteConfig('CUSTOM_EXTERNAL_CSS')
const CUSTOM_EXTERNAL_JS = siteConfig('CUSTOM_EXTERNAL_JS')
// 默认关闭NProgress
const ENABLE_NPROGRSS = siteConfig('ENABLE_NPROGRSS', false)
const COZE_BOT_ID = siteConfig('COZE_BOT_ID')
// 自定义样式css和js引入
if (isBrowser) {
// 初始化AOS动画
// 静态导入本地自定义样式
loadExternalResource('/css/custom.css', 'css')
loadExternalResource('/js/custom.js', 'js')
// 自动添加图片阴影
if (IMG_SHADOW) {
loadExternalResource('/css/img-shadow.css', 'css')
}
if (ANIMATE_CSS_URL) {
loadExternalResource(ANIMATE_CSS_URL, 'css')
}
// 导入外部自定义脚本
if (CUSTOM_EXTERNAL_JS && CUSTOM_EXTERNAL_JS.length > 0) {
for (const url of CUSTOM_EXTERNAL_JS) {
loadExternalResource(url, 'js')
}
}
// 导入外部自定义样式
if (CUSTOM_EXTERNAL_CSS && CUSTOM_EXTERNAL_CSS.length > 0) {
for (const url of CUSTOM_EXTERNAL_CSS) {
loadExternalResource(url, 'css')
}
}
}
const router = useRouter()
useEffect(() => {
// 异步渲染谷歌广告
if (ADSENSE_GOOGLE_ID) {
setTimeout(() => {
initGoogleAdsense(ADSENSE_GOOGLE_ID)
}, 3000)
}
setTimeout(() => {
// 映射url
convertInnerUrl(props?.allNavPages)
}, 500)
}, [router])
useEffect(() => {
// 执行注入脚本
// eslint-disable-next-line no-eval
eval(GLOBAL_JS)
}, [])
if (DISABLE_PLUGIN) {
return null
}
return (
<>
{/* 全局样式嵌入 */}
<GlobalStyle />
{MOUSE_FOLLOW && <MouseFollow />}
{THEME_SWITCH && <ThemeSwitch />}
{DEBUG && <DebugPanel />}
{ANALYTICS_ACKEE_TRACKER && <Ackee />}
{ANALYTICS_GOOGLE_ID && <Gtag />}
{ANALYTICS_VERCEL && <Analytics />}
{ANALYTICS_BUSUANZI_ENABLE && <Busuanzi />}
{FACEBOOK_APP_ID && FACEBOOK_PAGE_ID && <Messenger />}
{FIREWORKS && <Fireworks />}
{SAKURA && <Sakura />}
{STARRY_SKY && <StarrySky />}
{MUSIC_PLAYER && <MusicPlayer />}
{NEST && <Nest />}
{FLUTTERINGRIBBON && <FlutteringRibbon />}
{COMMENT_TWIKOO_COUNT_ENABLE && <TwikooCommentCounter {...props} />}
{RIBBON && <Ribbon />}
{DIFY_CHATBOT_ENABLED && <DifyChatbot />}
{CUSTOM_RIGHT_CLICK_CONTEXT_MENU && <CustomContextMenu {...props} />}
{!CAN_COPY && <DisableCopy />}
{WEB_WHIZ_ENABLED && <WebWhiz />}
{AD_WWADS_BLOCK_DETECT && <AdBlockDetect />}
{TIANLI_KEY && <TianliGPT />}
<VConsole />
{ENABLE_NPROGRSS && <LoadingProgress />}
<AosAnimation />
{ANALYTICS_51LA_ID && ANALYTICS_51LA_CK && <LA51 />}
{COZE_BOT_ID && <Coze />}
{ANALYTICS_51LA_ID && ANALYTICS_51LA_CK && (
<>
<script id='LA_COLLECT' src='//sdk.51.la/js-sdk-pro.min.js' defer />
{/* <script async dangerouslySetInnerHTML={{
__html: `
LA.init({id:"${ANALYTICS_51LA_ID}",ck:"${ANALYTICS_51LA_CK}",hashMode:true,autoTrack:true})
`
}} /> */}
</>
)}
{CHATBASE_ID && (
<>
<script
id={CHATBASE_ID}
src='https://www.chatbase.co/embed.min.js'
defer
/>
<script
async
dangerouslySetInnerHTML={{
__html: `
window.chatbaseConfig = {
chatbotId: "${CHATBASE_ID}",
}
`
}}
/>
</>
)}
{CLARITY_ID && (
<>
<script
async
dangerouslySetInnerHTML={{
__html: `
(function(c, l, a, r, i, t, y) {
c[a] = c[a] || function() {
(c[a].q = c[a].q || []).push(arguments);
};
t = l.createElement(r);
t.async = 1;
t.src = "https://www.clarity.ms/tag/" + i;
y = l.getElementsByTagName(r)[0];
if (y && y.parentNode) {
y.parentNode.insertBefore(t, y);
} else {
l.head.appendChild(t);
}
})(window, document, "clarity", "script", "${CLARITY_ID}");
`
}}
/>
</>
)}
{COMMENT_DAO_VOICE_ID && (
<>
{/* DaoVoice 反馈 */}
<script
async
dangerouslySetInnerHTML={{
__html: `
(function(i, s, o, g, r, a, m) {
i["DaoVoiceObject"] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments);
};
i[r].l = 1 * new Date();
a = s.createElement(o);
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
a.charset = "utf-8";
if (m && m.parentNode) {
m.parentNode.insertBefore(a, m);
} else {
s.head.appendChild(a);
}
})(window, document, "script", ('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/daf1a94b.js", "daovoice")
`
}}
/>
<script
async
dangerouslySetInnerHTML={{
__html: `
daovoice('init', {
app_id: "${COMMENT_DAO_VOICE_ID}"
});
daovoice('update');
`
}}
/>
</>
)}
{AD_WWADS_ID && (
<>
<Head>
{/* 提前连接到广告服务器 */}
<link rel='preconnect' href='https://cdn.wwads.cn' />
</Head>
<ExternalScript
type='text/javascript'
src='https://cdn.wwads.cn/js/makemoney.js'
/>
</>
)}
{/* {COMMENT_TWIKOO_ENV_ID && <script defer src={COMMENT_TWIKOO_CDN_URL} />} */}
{COMMENT_ARTALK_SERVER && <script defer src={COMMENT_ARTALK_JS} />}
{COMMENT_TIDIO_ID && (
<script async src={`//code.tidio.co/${COMMENT_TIDIO_ID}.js`} />
)}
{/* gitter聊天室 */}
{COMMENT_GITTER_ROOM && (
<>
<script
src='https://sidecar.gitter.im/dist/sidecar.v1.js'
async
defer
/>
<script
async
dangerouslySetInnerHTML={{
__html: `
((window.gitter = {}).chat = {}).options = {
room: '${COMMENT_GITTER_ROOM}'
};
`
}}
/>
</>
)}
{/* 百度统计 */}
{ANALYTICS_BAIDU_ID && (
<script
async
dangerouslySetInnerHTML={{
__html: `
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?${ANALYTICS_BAIDU_ID}";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
`
}}
/>
)}
{/* 站长统计 */}
{ANALYTICS_CNZZ_ID && (
<script
async
dangerouslySetInnerHTML={{
__html: `
document.write(unescape("%3Cspan style='display:none' id='cnzz_stat_icon_${ANALYTICS_CNZZ_ID}'%3E%3C/span%3E%3Cscript src='https://s9.cnzz.com/z_stat.php%3Fid%3D${ANALYTICS_CNZZ_ID}' type='text/javascript'%3E%3C/script%3E"));
`
}}
/>
)}
{/* 谷歌统计 */}
{ANALYTICS_GOOGLE_ID && (
<>
<script
async
src={`https://www.googletagmanager.com/gtag/js?id=${ANALYTICS_GOOGLE_ID}`}
/>
<script
async
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${ANALYTICS_GOOGLE_ID}', {
page_path: window.location.pathname,
});
`
}}
/>
</>
)}
{/* Matomo 统计 */}
{MATOMO_HOST_URL && MATOMO_SITE_ID && (
<script
async
dangerouslySetInnerHTML={{
__html: `
var _paq = window._paq = window._paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//${MATOMO_HOST_URL}/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '${MATOMO_SITE_ID}']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
`
}}
/>
)}
</>
)
}
const TwikooCommentCounter = dynamic(
() => import('@/components/TwikooCommentCounter'),
{ ssr: false }
)
const DebugPanel = dynamic(() => import('@/components/DebugPanel'), {
ssr: false
})
const ThemeSwitch = dynamic(() => import('@/components/ThemeSwitch'), {
ssr: false
})
const Fireworks = dynamic(() => import('@/components/Fireworks'), {
ssr: false
})
const MouseFollow = dynamic(() => import('@/components/MouseFollow'), {
ssr: false
})
const Nest = dynamic(() => import('@/components/Nest'), { ssr: false })
const FlutteringRibbon = dynamic(
() => import('@/components/FlutteringRibbon'),
{ ssr: false }
)
const Ribbon = dynamic(() => import('@/components/Ribbon'), { ssr: false })
const Sakura = dynamic(() => import('@/components/Sakura'), { ssr: false })
const StarrySky = dynamic(() => import('@/components/StarrySky'), {
ssr: false
})
const DifyChatbot = dynamic(() => import('@/components/DifyChatbot'), {
ssr: false
})
const Analytics = dynamic(
() =>
import('@vercel/analytics/react').then(async m => {
return m.Analytics
}),
{ ssr: false }
)
const MusicPlayer = dynamic(() => import('@/components/Player'), { ssr: false })
const Ackee = dynamic(() => import('@/components/Ackee'), { ssr: false })
const Gtag = dynamic(() => import('@/components/Gtag'), { ssr: false })
const Busuanzi = dynamic(() => import('@/components/Busuanzi'), { ssr: false })
const Messenger = dynamic(() => import('@/components/FacebookMessenger'), {
ssr: false
})
const VConsole = dynamic(() => import('@/components/VConsole'), { ssr: false })
const CustomContextMenu = dynamic(
() => import('@/components/CustomContextMenu'),
{ ssr: false }
)
const DisableCopy = dynamic(() => import('@/components/DisableCopy'), {
ssr: false
})
const AdBlockDetect = dynamic(() => import('@/components/AdBlockDetect'), {
ssr: false
})
const LoadingProgress = dynamic(() => import('@/components/LoadingProgress'), {
ssr: false
})
const AosAnimation = dynamic(() => import('@/components/AOSAnimation'), {
ssr: false
})
const Coze = dynamic(() => import('@/components/Coze'), {
ssr: false
})
const LA51 = dynamic(() => import('@/components/LA51'), {
ssr: false
})
const TianliGPT = dynamic(() => import('@/components/TianliGPT'), {
ssr: false
})
export default ExternalPlugin