From 9dd1cb6eebf85c272b8518eb9503e763aa853203 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Thu, 3 Mar 2022 21:28:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E8=AF=95=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/DebugButton.js | 50 +++++++++++++++++++++++++++++++++++++++ pages/_app.js | 2 ++ 2 files changed, 52 insertions(+) create mode 100644 components/DebugButton.js 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) && }