From 93be76e00838962eb5bb5ba58378ab217628d2e0 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Sun, 21 Jan 2024 20:12:57 +0800 Subject: [PATCH] =?UTF-8?q?GlobalJS=EF=BC=8CGlobalStyle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/ExternalPlugins.js | 41 +++++++++++++++++++++++++++++++++++ components/GlobalStyle.js | 20 +++++++++++++++++ lib/cache/cache_manager.js | 4 ++-- pages/_app.js | 30 +------------------------ 4 files changed, 64 insertions(+), 31 deletions(-) create mode 100644 components/GlobalStyle.js diff --git a/components/ExternalPlugins.js b/components/ExternalPlugins.js index 0ec4e0d9930..77433f972c2 100644 --- a/components/ExternalPlugins.js +++ b/components/ExternalPlugins.js @@ -3,6 +3,10 @@ import dynamic from 'next/dynamic' import LA51 from './LA51' import WebWhiz from './Webwhiz' import TianLiGPT from './TianliGPT' +import { GlobalStyle } from './GlobalStyle' + +import { CUSTOM_EXTERNAL_CSS, CUSTOM_EXTERNAL_JS, IMG_SHADOW } from '@/blog.config' +import { isBrowser, loadExternalResource } from '@/lib/utils' const TwikooCommentCounter = dynamic(() => import('@/components/TwikooCommentCounter'), { ssr: false }) const DebugPanel = dynamic(() => import('@/components/DebugPanel'), { ssr: false }) @@ -73,12 +77,44 @@ const ExternalPlugin = (props) => { 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') + + // 自定义样式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 (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') + } + } + } if (DISABLE_PLUGIN) { return null } return <> + + {/* 全局样式嵌入 */} + + {THEME_SWITCH && } {DEBUG && } {ANALYTICS_ACKEE_TRACKER && } @@ -115,6 +151,11 @@ const ExternalPlugin = (props) => { }} /> */} )} + {/* 注入JS脚本 */} + {GLOBAL_JS &&