mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-17 23:16:50 +00:00
common-script 配置化
This commit is contained in:
@@ -63,6 +63,7 @@ const ValineComponent = dynamic(() => import('@/components/ValineComponent'), {
|
||||
const Comment = ({ siteInfo, frontMatter, className }) => {
|
||||
const router = useRouter()
|
||||
|
||||
// 当连接中有特殊参数时跳转到评论区
|
||||
if (isBrowser && ('giscus' in router.query || router.query.target === 'comment')) {
|
||||
setTimeout(() => {
|
||||
const url = router.asPath.replace('?target=comment', '')
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
import BLOG from '@/blog.config'
|
||||
|
||||
/**
|
||||
* 统计脚本
|
||||
* @returns {JSX.Element}
|
||||
* @constructor
|
||||
*/
|
||||
const CommonScript = () => {
|
||||
return (<>
|
||||
|
||||
{BLOG.CHATBASE_ID && (<>
|
||||
<script id={BLOG.CHATBASE_ID} src="https://www.chatbase.co/embed.min.js" defer/>
|
||||
<script async dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
window.chatbaseConfig = {
|
||||
chatbotId: "${BLOG.CHATBASE_ID}",
|
||||
}
|
||||
`
|
||||
}}/>
|
||||
</>)}
|
||||
|
||||
{BLOG.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";m.parentNode.insertBefore(a,m)})(window,document,"script",('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/daf1a94b.js","daovoice")
|
||||
`
|
||||
}}
|
||||
/>
|
||||
<script async dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
daovoice('init', {
|
||||
app_id: "${BLOG.COMMENT_DAO_VOICE_ID}"
|
||||
});
|
||||
daovoice('update');
|
||||
`
|
||||
}}
|
||||
/>
|
||||
</>)}
|
||||
|
||||
{BLOG.AD_WWADS_ID && <script type="text/javascript" charSet="UTF-8" src="https://cdn.wwads.cn/js/makemoney.js" async></script>}
|
||||
|
||||
{BLOG.COMMENT_CUSDIS_APP_ID && <script defer src={`https://cusdis.com/js/widget/lang/${BLOG.LANG.toLowerCase()}.js`} />}
|
||||
|
||||
{BLOG.COMMENT_TWIKOO_ENV_ID && <script defer src={BLOG.COMMENT_TWIKOO_CDN_URL}/> }
|
||||
|
||||
{BLOG.COMMENT_ARTALK_SERVER && <script defer src={BLOG.COMMENT_ARTALK_JS}/> }
|
||||
|
||||
{BLOG.COMMENT_TIDIO_ID && <script async src={`//code.tidio.co/${BLOG.COMMENT_TIDIO_ID}.js`} />}
|
||||
|
||||
{/* gitter聊天室 */}
|
||||
{BLOG.COMMENT_GITTER_ROOM && (<>
|
||||
<script src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer/>
|
||||
<script async dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
((window.gitter = {}).chat = {}).options = {
|
||||
room: '${BLOG.COMMENT_GITTER_ROOM}'
|
||||
};
|
||||
`
|
||||
}}/>
|
||||
</>)}
|
||||
|
||||
{/* 百度统计 */}
|
||||
{BLOG.ANALYTICS_BAIDU_ID && (
|
||||
<script async
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
var _hmt = _hmt || [];
|
||||
(function() {
|
||||
var hm = document.createElement("script");
|
||||
hm.src = "https://hm.baidu.com/hm.js?${BLOG.ANALYTICS_BAIDU_ID}";
|
||||
var s = document.getElementsByTagName("script")[0];
|
||||
s.parentNode.insertBefore(hm, s);
|
||||
})();
|
||||
`
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 站长统计 */}
|
||||
{BLOG.ANALYTICS_CNZZ_ID && (
|
||||
<script async
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
document.write(unescape("%3Cspan style='display:none' id='cnzz_stat_icon_${BLOG.ANALYTICS_CNZZ_ID}'%3E%3C/span%3E%3Cscript src='https://s9.cnzz.com/z_stat.php%3Fid%3D${BLOG.ANALYTICS_CNZZ_ID}' type='text/javascript'%3E%3C/script%3E"));
|
||||
`
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 谷歌统计 */}
|
||||
{BLOG.ANALYTICS_GOOGLE_ID && (<>
|
||||
<script async
|
||||
src={`https://www.googletagmanager.com/gtag/js?id=${BLOG.ANALYTICS_GOOGLE_ID}`}
|
||||
/>
|
||||
<script async
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
gtag('config', '${BLOG.ANALYTICS_GOOGLE_ID}', {
|
||||
page_path: window.location.pathname,
|
||||
});
|
||||
`
|
||||
}}
|
||||
/>
|
||||
</>)}
|
||||
|
||||
</>)
|
||||
}
|
||||
|
||||
export default CommonScript
|
||||
@@ -5,18 +5,23 @@ import { loadExternalResource } from '@/lib/utils'
|
||||
import { siteConfig } from '@/lib/config'
|
||||
|
||||
const CusdisComponent = ({ frontMatter }) => {
|
||||
const { lang } = useGlobal()
|
||||
const router = useRouter()
|
||||
const { isDarkMode } = useGlobal()
|
||||
const { isDarkMode, lang } = useGlobal()
|
||||
const src = siteConfig('COMMENT_CUSDIS_SCRIPT_SRC')
|
||||
const i18nForCusdis = siteConfig('LANG').toLowerCase().indexOf('zh') === 0 ? siteConfig('LANG').toLowerCase() : siteConfig('LANG').toLowerCase().substring(0, 2)
|
||||
const langCDN = siteConfig('COMMENT_CUSDIS_LANG_SRC', `https://cusdis.com/js/widget/lang/${i18nForCusdis}.js`)
|
||||
|
||||
// 处理cusdis主题
|
||||
useEffect(() => {
|
||||
loadExternalResource(src, 'js').then(url => {
|
||||
const CUSDIS = window.CUSDIS
|
||||
CUSDIS?.initial()
|
||||
})
|
||||
}, [isDarkMode])
|
||||
loadCusdis()
|
||||
}, [isDarkMode, lang])
|
||||
|
||||
const loadCusdis = async () => {
|
||||
await loadExternalResource(langCDN, 'js')
|
||||
await loadExternalResource(src, 'js')
|
||||
|
||||
window?.CUSDIS?.initial()
|
||||
}
|
||||
|
||||
return <div id="cusdis_thread"
|
||||
lang={lang.toLowerCase()}
|
||||
|
||||
@@ -30,28 +30,126 @@ const AdBlockDetect = dynamic(() => import('@/components/AdBlockDetect'), { ssr:
|
||||
*/
|
||||
const ExternalPlugin = (props) => {
|
||||
return <>
|
||||
{JSON.parse(siteConfig('THEME_SWITCH')) && <ThemeSwitch />}
|
||||
{JSON.parse(siteConfig('DEBUG')) && <DebugPanel />}
|
||||
{siteConfig('ANALYTICS_ACKEE_TRACKER') && <Ackee />}
|
||||
{siteConfig('ANALYTICS_GOOGLE_ID') && <Gtag />}
|
||||
{siteConfig('ANALYTICS_VERCEL') && <Analytics />}
|
||||
{JSON.parse(siteConfig('ANALYTICS_BUSUANZI_ENABLE')) && <Busuanzi />}
|
||||
{siteConfig('ADSENSE_GOOGLE_ID') && <GoogleAdsense />}
|
||||
{siteConfig('FACEBOOK_APP_ID') && siteConfig('FACEBOOK_PAGE_ID') && <Messenger />}
|
||||
{JSON.parse(siteConfig('FIREWORKS')) && <Fireworks />}
|
||||
{JSON.parse(siteConfig('SAKURA')) && <Sakura />}
|
||||
{JSON.parse(siteConfig('STARRY_SKY')) && <StarrySky />}
|
||||
{JSON.parse(siteConfig('MUSIC_PLAYER')) && <MusicPlayer />}
|
||||
{JSON.parse(siteConfig('NEST')) && <Nest />}
|
||||
{JSON.parse(siteConfig('FLUTTERINGRIBBON')) && <FlutteringRibbon />}
|
||||
{JSON.parse(siteConfig('COMMENT_TWIKOO_COUNT_ENABLE')) && <TwikooCommentCounter {...props}/>}
|
||||
{JSON.parse(siteConfig('RIBBON')) && <Ribbon />}
|
||||
{JSON.parse(siteConfig('CUSTOM_RIGHT_CLICK_CONTEXT_MENU')) && <CustomContextMenu {...props} />}
|
||||
{!JSON.parse(siteConfig('CAN_COPY')) && <DisableCopy/>}
|
||||
{JSON.parse(siteConfig('WEB_WHIZ_ENABLED')) && <WebWhiz/>}
|
||||
{JSON.parse(siteConfig('AD_WWADS_BLOCK_DETECT')) && <AdBlockDetect/>}
|
||||
<VConsole/>
|
||||
</>
|
||||
{JSON.parse(siteConfig('THEME_SWITCH')) && <ThemeSwitch />}
|
||||
{JSON.parse(siteConfig('DEBUG')) && <DebugPanel />}
|
||||
{siteConfig('ANALYTICS_ACKEE_TRACKER') && <Ackee />}
|
||||
{siteConfig('ANALYTICS_GOOGLE_ID') && <Gtag />}
|
||||
{siteConfig('ANALYTICS_VERCEL') && <Analytics />}
|
||||
{JSON.parse(siteConfig('ANALYTICS_BUSUANZI_ENABLE')) && <Busuanzi />}
|
||||
{siteConfig('ADSENSE_GOOGLE_ID') && <GoogleAdsense />}
|
||||
{siteConfig('FACEBOOK_APP_ID') && siteConfig('FACEBOOK_PAGE_ID') && <Messenger />}
|
||||
{JSON.parse(siteConfig('FIREWORKS')) && <Fireworks />}
|
||||
{JSON.parse(siteConfig('SAKURA')) && <Sakura />}
|
||||
{JSON.parse(siteConfig('STARRY_SKY')) && <StarrySky />}
|
||||
{JSON.parse(siteConfig('MUSIC_PLAYER')) && <MusicPlayer />}
|
||||
{JSON.parse(siteConfig('NEST')) && <Nest />}
|
||||
{JSON.parse(siteConfig('FLUTTERINGRIBBON')) && <FlutteringRibbon />}
|
||||
{JSON.parse(siteConfig('COMMENT_TWIKOO_COUNT_ENABLE')) && <TwikooCommentCounter {...props} />}
|
||||
{JSON.parse(siteConfig('RIBBON')) && <Ribbon />}
|
||||
{JSON.parse(siteConfig('CUSTOM_RIGHT_CLICK_CONTEXT_MENU')) && <CustomContextMenu {...props} />}
|
||||
{!JSON.parse(siteConfig('CAN_COPY')) && <DisableCopy />}
|
||||
{JSON.parse(siteConfig('WEB_WHIZ_ENABLED')) && <WebWhiz />}
|
||||
{JSON.parse(siteConfig('AD_WWADS_BLOCK_DETECT')) && <AdBlockDetect />}
|
||||
<VConsole />
|
||||
|
||||
{siteConfig('CHATBASE_ID') && (<>
|
||||
<script id={siteConfig('CHATBASE_ID')} src="https://www.chatbase.co/embed.min.js" defer />
|
||||
<script async dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
window.chatbaseConfig = {
|
||||
chatbotId: "${siteConfig('CHATBASE_ID')}",
|
||||
}
|
||||
`
|
||||
}} />
|
||||
</>)}
|
||||
|
||||
{siteConfig('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";m.parentNode.insertBefore(a,m)})(window,document,"script",('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/daf1a94b.js","daovoice")
|
||||
`
|
||||
}}
|
||||
/>
|
||||
<script async dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
daovoice('init', {
|
||||
app_id: "${siteConfig('COMMENT_DAO_VOICE_ID')}"
|
||||
});
|
||||
daovoice('update');
|
||||
`
|
||||
}}
|
||||
/>
|
||||
</>)}
|
||||
|
||||
{siteConfig('AD_WWADS_ID') && <script type="text/javascript" charSet="UTF-8" src="https://cdn.wwads.cn/js/makemoney.js" async></script>}
|
||||
|
||||
{siteConfig('COMMENT_TWIKOO_ENV_ID') && <script defer src={siteConfig('COMMENT_TWIKOO_CDN_URL')} />}
|
||||
|
||||
{siteConfig('COMMENT_ARTALK_SERVER') && <script defer src={siteConfig('COMMENT_ARTALK_JS')} />}
|
||||
|
||||
{siteConfig('COMMENT_TIDIO_ID') && <script async src={`//code.tidio.co/${siteConfig('COMMENT_TIDIO_ID')}.js`} />}
|
||||
|
||||
{/* gitter聊天室 */}
|
||||
{siteConfig('COMMENT_GITTER_ROOM') && (<>
|
||||
<script src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer />
|
||||
<script async dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
((window.gitter = {}).chat = {}).options = {
|
||||
room: '${siteConfig('COMMENT_GITTER_ROOM')}'
|
||||
};
|
||||
`
|
||||
}} />
|
||||
</>)}
|
||||
|
||||
{/* 百度统计 */}
|
||||
{siteConfig('ANALYTICS_BAIDU_ID') && (
|
||||
<script async
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
var _hmt = _hmt || [];
|
||||
(function() {
|
||||
var hm = document.createElement("script");
|
||||
hm.src = "https://hm.baidu.com/hm.js?${siteConfig('ANALYTICS_BAIDU_ID')}";
|
||||
var s = document.getElementsByTagName("script")[0];
|
||||
s.parentNode.insertBefore(hm, s);
|
||||
})();
|
||||
`
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 站长统计 */}
|
||||
{siteConfig('ANALYTICS_CNZZ_ID') && (
|
||||
<script async
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
document.write(unescape("%3Cspan style='display:none' id='cnzz_stat_icon_${siteConfig('ANALYTICS_CNZZ_ID')}'%3E%3C/span%3E%3Cscript src='https://s9.cnzz.com/z_stat.php%3Fid%3D${siteConfig('ANALYTICS_CNZZ_ID')}' type='text/javascript'%3E%3C/script%3E"));
|
||||
`
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 谷歌统计 */}
|
||||
{siteConfig('ANALYTICS_GOOGLE_ID') && (<>
|
||||
<script async
|
||||
src={`https://www.googletagmanager.com/gtag/js?id=${siteConfig('ANALYTICS_GOOGLE_ID')}`}
|
||||
/>
|
||||
<script async
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
gtag('config', '${siteConfig('ANALYTICS_GOOGLE_ID')}', {
|
||||
page_path: window.location.pathname,
|
||||
});
|
||||
`
|
||||
}}
|
||||
/>
|
||||
</>)}
|
||||
|
||||
</>
|
||||
}
|
||||
|
||||
export default ExternalPlugin
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import BLOG from '@/blog.config'
|
||||
import { siteConfig } from '@/lib/config'
|
||||
import { useGlobal } from '@/lib/global'
|
||||
import Giscus from '@giscus/react'
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import React from 'react'
|
||||
import { siteConfig } from '@/lib/config'
|
||||
|
||||
/**
|
||||
@@ -8,11 +7,13 @@ import { siteConfig } from '@/lib/config'
|
||||
* @returns {JSX.Element | null} - 返回渲染的 JSX 元素或 null
|
||||
*/
|
||||
export default function WWAds({ orientation = 'vertical', sticky = false, className }) {
|
||||
if (!JSON.parse(siteConfig('AD_WWADS_ID'))) {
|
||||
const adWWADSId = siteConfig('AD_WWADS_ID')
|
||||
|
||||
if (!adWWADSId) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={`wwads-cn ${orientation === 'vertical' ? 'wwads-vertical' : 'wwads-horizontal'} ${sticky ? 'wwads-sticky' : ''} z-10 ${className || ''}`} data-id={siteConfig('AD_WWADS_ID')}></div>
|
||||
)
|
||||
return <div data-id={adWWADSId} className={`wwads-cn
|
||||
${orientation === 'vertical' ? 'wwads-vertical' : 'wwads-horizontal'}
|
||||
${sticky ? 'wwads-sticky' : ''} z-10 ${className || ''}`} />
|
||||
}
|
||||
|
||||
@@ -91,6 +91,7 @@ module.exports = withBundleAnalyzer({
|
||||
// })
|
||||
// }
|
||||
// 动态主题:添加 resolve.alias 配置,将动态路径映射到实际路径
|
||||
console.log('加载默认主题', path.resolve(__dirname, 'themes', THEME))
|
||||
config.resolve.alias['@theme-components'] = path.resolve(__dirname, 'themes', THEME)
|
||||
return config
|
||||
},
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// eslint-disable-next-line @next/next/no-document-import-in-page
|
||||
import Document, { Html, Head, Main, NextScript } from 'next/document'
|
||||
import BLOG from '@/blog.config'
|
||||
import CommonScript from '@/components/CommonScript'
|
||||
|
||||
class MyDocument extends Document {
|
||||
static async getInitialProps(ctx) {
|
||||
@@ -14,7 +13,6 @@ class MyDocument extends Document {
|
||||
<Html lang={BLOG.LANG}>
|
||||
<Head>
|
||||
<link rel='icon' href= {`${BLOG.BLOG_FAVICON}`} />
|
||||
<CommonScript />
|
||||
{/* 预加载字体 */}
|
||||
{BLOG.FONT_AWESOME && <>
|
||||
<link rel='preload' href={BLOG.FONT_AWESOME} as="style" crossOrigin="anonymous" />
|
||||
|
||||
@@ -15,8 +15,8 @@ export const MenuItemDrop = ({ link }) => {
|
||||
<Link
|
||||
href={link?.to} target={link?.to?.indexOf('http') === 0 ? '_blank' : '_self'}
|
||||
className="font-sans menu-link pl-2 pr-4 text-gray-700 dark:text-gray-200 no-underline tracking-widest pb-1">
|
||||
<>{link?.icon && <span className='mr-2'><i className={link.icon} /></span>}{link?.name}
|
||||
{hasSubMenu && <i className='px-2 fa fa-angle-down'></i>}</>
|
||||
{link?.icon && <span className='mr-2'><i className={link.icon} /></span>}{link?.name}
|
||||
{hasSubMenu && <i className='px-2 fa fa-angle-down'></i>}
|
||||
</Link>}
|
||||
|
||||
{hasSubMenu && <>
|
||||
|
||||
Reference in New Issue
Block a user