diff --git a/lib/font.js b/lib/font.js index d485eebd..05ba86ff 100644 --- a/lib/font.js +++ b/lib/font.js @@ -50,4 +50,4 @@ const fontFamilies = { ] } -module.exports = fontFamilies +module.exports = { fontFamilies } diff --git a/pages/_app.js b/pages/_app.js index 9a3969a3..79506c43 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -23,6 +23,8 @@ import { GlobalContextProvider } from '@/lib/global' import { DebugPanel } from '@/components/DebugPanel' import { ThemeSwitch } from '@/components/ThemeSwitch' import { Fireworks } from '@/components/Fireworks' +import React from 'react' +import { loadExternalResource } from '@/lib/utils' const Ackee = dynamic(() => import('@/components/Ackee'), { ssr: false }) const Gtag = dynamic(() => import('@/components/Gtag'), { ssr: false }) @@ -47,14 +49,26 @@ const MyApp = ({ Component, pageProps }) => { {JSON.parse(BLOG.FIREWORKS) && } + // 延迟加载字体 + React.useEffect(() => { + loadFont() + }, []) + return ( - {/* FontawesomeCDN */} - {externalPlugins} ) } +/** + * 延迟加载字体 + */ +const loadFont = () => { + loadExternalResource(BLOG.FONT_AWESOME_PATH, 'css') + for (const fontUrl of BLOG.CUSTOM_FONT_URL) { + loadExternalResource(fontUrl, 'css') + } +} export default MyApp diff --git a/pages/_document.js b/pages/_document.js index 7aae613a..4438697e 100644 --- a/pages/_document.js +++ b/pages/_document.js @@ -15,10 +15,6 @@ class MyDocument extends Document { - { BLOG.CUSTOM_FONT - ? BLOG.CUSTOM_FONT_URL?.map(fontUrl => - ) - : }