From 351878dc1372793f2e96dad30b20b7733a882961 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Sun, 4 Jun 2023 18:08:14 +0800 Subject: [PATCH] async theme --- components/Live2D.js | 6 +++++- components/Loading.js | 13 +++++++++---- components/PrismMac.js | 2 +- pages/404.js | 2 +- pages/[...slug].js | 2 +- pages/archive/index.js | 2 +- pages/category/[category]/index.js | 4 ++-- pages/category/[category]/page/[page].js | 4 ++-- pages/index.js | 4 ++-- pages/page/[page].js | 2 +- pages/search/[keyword]/index.js | 2 +- pages/search/[keyword]/page/[page].js | 2 +- pages/search/index.js | 2 +- pages/tag/[tag]/index.js | 4 ++-- pages/tag/[tag]/page/[page].js | 4 ++-- pages/tag/index.js | 2 +- 16 files changed, 33 insertions(+), 24 deletions(-) diff --git a/components/Live2D.js b/components/Live2D.js index 4826a11b..f75c5438 100644 --- a/components/Live2D.js +++ b/components/Live2D.js @@ -14,7 +14,11 @@ export default function Live2D() { ]).then((e) => { if (typeof window?.loadlive2d !== 'undefined') { // https://github.com/xiazeyu/live2d-widget-models - loadlive2d('live2d', BLOG.WIDGET_PET_LINK) + try { + loadlive2d('live2d', BLOG.WIDGET_PET_LINK) + } catch (error) { + + } } }) } diff --git a/components/Loading.js b/components/Loading.js index 57ccf401..d7cb08e3 100644 --- a/components/Loading.js +++ b/components/Loading.js @@ -1,10 +1,15 @@ + /** * 主题文件被加载出之前的占位符 * @returns */ -const Loading = () => { - return
-

Loading...

-
+const Loading = (props) => { + const { current } = props + + return <> + {current ||
+

Loading...

+
} + } export default Loading diff --git a/components/PrismMac.js b/components/PrismMac.js index 8a4a4c51..c8a93c49 100644 --- a/components/PrismMac.js +++ b/components/PrismMac.js @@ -25,7 +25,7 @@ const PrismMac = () => { } loadExternalResource(BLOG.PRISM_THEME_PATH, 'css') loadExternalResource(BLOG.PRISM_JS_AUTO_LOADER, 'js').then((url) => { - console.log('渲染公式图表') + // console.log('渲染公式图表') if (window?.Prism?.plugins?.autoloader) { window.Prism.plugins.autoloader.languages_path = BLOG.PRISM_JS_PATH } diff --git a/pages/404.js b/pages/404.js index 02861a40..3afa60ee 100644 --- a/pages/404.js +++ b/pages/404.js @@ -11,7 +11,7 @@ import Loading from '@/components/Loading' const NoFound = props => { const { theme, siteInfo } = useGlobal() const meta = { title: `${props?.siteInfo?.title} | 页面找不到啦`, image: siteInfo?.pageCover } - const Layout404 = dynamic(() => import(`@/themes/${theme}/Layout404`).then(async (m) => { return m.Layout404 }), { ssr: false, loading: () => }) + const Layout404 = dynamic(() => import(`@/themes/${theme}/Layout404`).then(async (m) => { return m.Layout404 }), { ssr: true, loading: () => }) return } diff --git a/pages/[...slug].js b/pages/[...slug].js index c3e58d78..00691796 100644 --- a/pages/[...slug].js +++ b/pages/[...slug].js @@ -24,7 +24,7 @@ const Slug = props => { // 文章锁🔐 const [lock, setLock] = useState(post?.password && post?.password !== '') - const LayoutSlug = dynamic(() => import(`@/themes/${theme}/LayoutSlug`).then(async (m) => { return m.LayoutSlug }), { ssr: false, loading: () => }) + const LayoutSlug = dynamic(() => import(`@/themes/${theme}`).then(async (m) => { return m.LayoutSlug }), { ssr: true, loading: () => }) useEffect(() => { changeLoadingState(false) diff --git a/pages/archive/index.js b/pages/archive/index.js index 8d20f44f..17b1fd80 100644 --- a/pages/archive/index.js +++ b/pages/archive/index.js @@ -16,7 +16,7 @@ const ArchiveIndex = props => { type: 'website' } - const LayoutArchive = dynamic(() => import(`@/themes/${theme}/LayoutArchive`).then(async (m) => { return m.LayoutArchive }), { ssr: false, loading: () => }) + const LayoutArchive = dynamic(() => import(`@/themes/${theme}/LayoutArchive`).then(async (m) => { return m.LayoutArchive }), { ssr: true, loading: () => }) return } diff --git a/pages/category/[category]/index.js b/pages/category/[category]/index.js index cd0a4403..246170b9 100644 --- a/pages/category/[category]/index.js +++ b/pages/category/[category]/index.js @@ -15,7 +15,7 @@ export default function Category(props) { const { siteInfo, posts } = props const { locale } = useGlobal() if (!posts) { - const Layout404 = dynamic(() => import(`@/themes/${theme}/Layout404`).then(async (m) => { return m.Layout404 }), { ssr: false, loading: () => }) + const Layout404 = dynamic(() => import(`@/themes/${theme}/Layout404`).then(async (m) => { return m.Layout404 }), { ssr: true, loading: () => }) return } const meta = { @@ -28,7 +28,7 @@ export default function Category(props) { type: 'website' } - const LayoutCategory = dynamic(() => import(`@/themes/${theme}/LayoutCategory`).then(async (m) => { return m.LayoutCategory }), { ssr: false, loading: () => }) + const LayoutCategory = dynamic(() => import(`@/themes/${theme}/LayoutCategory`).then(async (m) => { return m.LayoutCategory }), { ssr: true, loading: () => }) return } diff --git a/pages/category/[category]/page/[page].js b/pages/category/[category]/page/[page].js index f1dd286b..f537448a 100644 --- a/pages/category/[category]/page/[page].js +++ b/pages/category/[category]/page/[page].js @@ -15,7 +15,7 @@ export default function Category(props) { const { siteInfo, posts } = props const { locale } = useGlobal() if (!posts) { - const Layout404 = dynamic(() => import(`@/themes/${theme}/Layout404`).then(async (m) => { return m.Layout404 }), { ssr: false, loading: () => }) + const Layout404 = dynamic(() => import(`@/themes/${theme}/Layout404`).then(async (m) => { return m.Layout404 }), { ssr: true, loading: () => }) return } const meta = { @@ -28,7 +28,7 @@ export default function Category(props) { type: 'website' } - const LayoutCategory = dynamic(() => import(`@/themes/${theme}/LayoutCategory`).then(async (m) => { return m.LayoutCategory }), { ssr: false, loading: () => }) + const LayoutCategory = dynamic(() => import(`@/themes/${theme}/LayoutCategory`).then(async (m) => { return m.LayoutCategory }), { ssr: true, loading: () => }) return } diff --git a/pages/index.js b/pages/index.js index e826dbd9..4fbd5673 100644 --- a/pages/index.js +++ b/pages/index.js @@ -14,8 +14,8 @@ import Loading from '@/components/Loading' */ const Index = props => { const { theme } = useGlobal() - const LayoutIndex = dynamic(() => import(`@/themes/${theme}/LayoutIndex`) - .then(async (m) => { return m.LayoutIndex }), { ssr: false, loading: () => } + const LayoutIndex = dynamic(() => import(`@/themes/${theme}`) + .then(async (m) => { return m.LayoutIndex }), { ssr: true, loading: () => } ) return } diff --git a/pages/page/[page].js b/pages/page/[page].js index 8af1642b..b94194fc 100644 --- a/pages/page/[page].js +++ b/pages/page/[page].js @@ -19,7 +19,7 @@ const Page = props => { type: 'website' } - const LayoutPage = dynamic(() => import(`@/themes/${theme}/LayoutPage`).then(async (m) => { return m.LayoutPage }), { ssr: false, loading: () => }) + const LayoutPage = dynamic(() => import(`@/themes/${theme}/LayoutPage`).then(async (m) => { return m.LayoutPage }), { ssr: true, loading: () => }) return } diff --git a/pages/search/[keyword]/index.js b/pages/search/[keyword]/index.js index e0ad07cd..a30ae812 100644 --- a/pages/search/[keyword]/index.js +++ b/pages/search/[keyword]/index.js @@ -17,7 +17,7 @@ const Index = props => { } const { theme } = useGlobal() - const LayoutSearch = dynamic(() => import(`@/themes/${theme}/LayoutSearch`).then(async (m) => { return m.LayoutSearch }), { ssr: false, loading: () => }) + const LayoutSearch = dynamic(() => import(`@/themes/${theme}/LayoutSearch`).then(async (m) => { return m.LayoutSearch }), { ssr: true, loading: () => }) return } diff --git a/pages/search/[keyword]/page/[page].js b/pages/search/[keyword]/page/[page].js index 54798107..188cc7b8 100644 --- a/pages/search/[keyword]/page/[page].js +++ b/pages/search/[keyword]/page/[page].js @@ -16,7 +16,7 @@ const Index = props => { type: 'website' } const { theme } = useGlobal() - const LayoutSearch = dynamic(() => import(`@/themes/${theme}/LayoutSearch`).then(async (m) => { return m.LayoutSearch }), { ssr: false, loading: () => }) + const LayoutSearch = dynamic(() => import(`@/themes/${theme}/LayoutSearch`).then(async (m) => { return m.LayoutSearch }), { ssr: true, loading: () => }) return } diff --git a/pages/search/index.js b/pages/search/index.js index f132748d..c7e4f53d 100644 --- a/pages/search/index.js +++ b/pages/search/index.js @@ -34,7 +34,7 @@ const Search = props => { const { theme } = useGlobal() - const LayoutSearch = dynamic(() => import(`@/themes/${theme}/LayoutSearch`).then(async (m) => { return m.LayoutSearch }), { ssr: false, loading: () => }) + const LayoutSearch = dynamic(() => import(`@/themes/${theme}/LayoutSearch`).then(async (m) => { return m.LayoutSearch }), { ssr: true, loading: () => }) return } diff --git a/pages/tag/[tag]/index.js b/pages/tag/[tag]/index.js index b87e954f..c12aace1 100644 --- a/pages/tag/[tag]/index.js +++ b/pages/tag/[tag]/index.js @@ -10,7 +10,7 @@ const Tag = props => { const { tag, siteInfo, posts } = props if (!posts) { - const Layout404 = dynamic(() => import(`@/themes/${theme}/Layout404`).then(async (m) => { return m.Layout404 }), { ssr: false, loading: () => }) + const Layout404 = dynamic(() => import(`@/themes/${theme}/Layout404`).then(async (m) => { return m.Layout404 }), { ssr: true, loading: () => }) return } @@ -21,7 +21,7 @@ const Tag = props => { slug: 'tag/' + tag, type: 'website' } - const LayoutTagIndex = dynamic(() => import(`@/themes/${theme}/LayoutTagIndex`).then(async (m) => { return m.LayoutTagIndex }), { ssr: false, loading: () => }) + const LayoutTagIndex = dynamic(() => import(`@/themes/${theme}/LayoutTagIndex`).then(async (m) => { return m.LayoutTagIndex }), { ssr: true, loading: () => }) return } diff --git a/pages/tag/[tag]/page/[page].js b/pages/tag/[tag]/page/[page].js index 45d01c84..7b89a2da 100644 --- a/pages/tag/[tag]/page/[page].js +++ b/pages/tag/[tag]/page/[page].js @@ -10,7 +10,7 @@ const Tag = props => { const { tag, siteInfo, posts } = props if (!posts) { - const Layout404 = dynamic(() => import(`@/themes/${theme}/Layout404`).then(async (m) => { return m.Layout404 }), { ssr: false, loading: () => }) + const Layout404 = dynamic(() => import(`@/themes/${theme}/Layout404`).then(async (m) => { return m.Layout404 }), { ssr: true, loading: () => }) return } @@ -21,7 +21,7 @@ const Tag = props => { slug: 'tag/' + tag, type: 'website' } - const LayoutTag = dynamic(() => import(`@/themes/${theme}/LayoutTag`).then(async (m) => { return m.LayoutTag }), { ssr: false, loading: () => }) + const LayoutTag = dynamic(() => import(`@/themes/${theme}/LayoutTag`).then(async (m) => { return m.LayoutTag }), { ssr: true, loading: () => }) return } diff --git a/pages/tag/index.js b/pages/tag/index.js index 1d2f3a29..e7299896 100644 --- a/pages/tag/index.js +++ b/pages/tag/index.js @@ -21,7 +21,7 @@ const TagIndex = props => { slug: 'tag', type: 'website' } - const LayoutTagIndex = dynamic(() => import(`@/themes/${theme}/LayoutTagIndex`).then(async (m) => { return m.LayoutTagIndex }), { ssr: false, loading: () => }) + const LayoutTagIndex = dynamic(() => import(`@/themes/${theme}/LayoutTagIndex`).then(async (m) => { return m.LayoutTagIndex }), { ssr: true, loading: () => }) return }