diff --git a/components/DebugButton.js b/components/DebugButton.js new file mode 100644 index 00000000..064d1991 --- /dev/null +++ b/components/DebugButton.js @@ -0,0 +1,50 @@ +import { useGlobal } from '@/lib/global' +import { ThemeMap } from '@/themes' +import { useState } from 'react' + +/** + * + * @returns 调试面板 + */ +export function DebugButton () { + const [show, setShow] = useState(false) + const GlobalConfig = useGlobal() + const { theme, setTheme } = GlobalConfig + const allThemes = Object.keys(ThemeMap) + function toggleShow () { + setShow(!show) + } + + /** + * 切换主题 + */ + function changeTheme () { + const currentIndex = allThemes.indexOf(theme) + const newIndex = currentIndex < allThemes.length - 1 ? currentIndex + 1 : 0 + setTheme(allThemes[newIndex]) + } + + return <> +
+
+
当前主题:
+
{theme}
+
+
+
所有主题:
+
{allThemes.join(',')}
+
+
+
更换主题
+
+
+
所有配置:
+

{JSON.stringify(GlobalConfig)}

+
+
+ +
+
调试按钮
+
+ +} diff --git a/pages/_app.js b/pages/_app.js index e5b63150..0f0948ed 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -14,6 +14,7 @@ import 'prismjs/themes/prism-okaidia.css' import 'katex/dist/katex.min.css' import dynamic from 'next/dynamic' import { GlobalContextProvider } from '@/lib/global' +import { DebugButton } from '@/components/DebugButton' const Ackee = dynamic(() => import('@/components/Ackee'), { ssr: false }) const Gtag = dynamic(() => import('@/components/Gtag'), { ssr: false }) @@ -23,6 +24,7 @@ const GoogleAdsense = dynamic(() => import('@/components/GoogleAdsense'), { ssr: const MyApp = ({ Component, pageProps }) => { return ( + {BLOG.DEBUG_BUTTON && } {BLOG.ANALYTICS_ACKEE_TRACKER && } {BLOG.ANALYTICS_GOOGLE_ID && } {JSON.parse(BLOG.ANALYTICS_BUSUANZI_ENABLE) && }