From 9d9d40f50d59bfd44f96f569f43c16cb5f42100e Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Fri, 18 Mar 2022 11:30:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9C=8B=E6=9D=BF=E5=AE=A0=E7=89=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog.config.js | 4 +++ .../next/components => components}/Live2D.js | 28 +++++++++++-------- pages/_app.js | 1 + themes/fukasawa/LayoutBase.js | 4 ++- themes/fukasawa/components/AsideLeft.js | 6 ++-- themes/hexo/LayoutBase.js | 4 ++- themes/hexo/components/SideRight.js | 20 ++++++------- themes/medium/LayoutBase.js | 10 ++++++- themes/next/LayoutArchive.js | 2 -- themes/next/LayoutBase.js | 4 ++- themes/next/LayoutSlug.js | 4 --- themes/next/components/SideAreaLeft.js | 10 +++++-- themes/next/config_next.js | 3 -- 13 files changed, 60 insertions(+), 40 deletions(-) rename {themes/next/components => components}/Live2D.js (53%) diff --git a/blog.config.js b/blog.config.js index 54ac8cd3..0b62db37 100644 --- a/blog.config.js +++ b/blog.config.js @@ -39,6 +39,10 @@ const BLOG = { CONTACT_GITHUB: 'https://github.com/tangly1024', CONTACT_TELEGRAM: '', + // 悬浮挂件 + WIDGET_PET: process.env.NEXT_PUBLIC_WIDGET_PET || false, // 是否显示宠物挂件 + WIDGET_PET_LINK: 'https://cdn.jsdelivr.net/npm/live2d-widget-model-wanko@1.0.5/assets/wanko.model.json', // 挂件模型地址 @see https://github.com/xiazeyu/live2d-widget-models + // 评论互动 可同时开启 CUSDIS UTTERRANCES GITALK COMMENT_CUSDIS_APP_ID: process.env.NEXT_PUBLIC_COMMENT_CUSDIS_APP_ID || '', // data-app-id 36位 see https://cusdis.com/ COMMENT_CUSDIS_HOST: process.env.NEXT_PUBLIC_COMMENT_CUSDIS_HOST || 'https://cusdis.com', // data-host, change this if you're using self-hosted version diff --git a/themes/next/components/Live2D.js b/components/Live2D.js similarity index 53% rename from themes/next/components/Live2D.js rename to components/Live2D.js index c9ce2a1b..e82ee884 100644 --- a/themes/next/components/Live2D.js +++ b/components/Live2D.js @@ -1,21 +1,27 @@ /* eslint-disable no-undef */ -import CONFIG_NEXT from '../config_next' +import BLOG from '@/blog.config' import { loadExternalResource } from '@/lib/utils' +import { useEffect, useState } from 'react' -let hasLoad = false export default function Live2D () { - if (!CONFIG_NEXT.WIDGET_PET) { + if (!BLOG.WIDGET_PET) { return <> } + const [init, setInit] = useState() - if (typeof window !== 'undefined' && !hasLoad) { - initLive2D() - hasLoad = true - } + // if (typeof window !== 'undefined' && !hasLoad) { + // initLive2D() + // hasLoad = true + // } - return
- -
+ useEffect(() => { + if (!init) { + initLive2D() + setInit(true) + } + }, [init]) + + return } function initLive2D () { @@ -26,7 +32,7 @@ function initLive2D () { loadExternalResource('https://cdn.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/live2d.min.js', 'js') ]).then(() => { // https://github.com/xiazeyu/live2d-widget-models - loadlive2d('live2d', CONFIG_NEXT.WIDGET_PET_LINK) + loadlive2d('live2d', BLOG.WIDGET_PET_LINK) }) } } diff --git a/pages/_app.js b/pages/_app.js index ecf1c2ad..02ed2d14 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -34,6 +34,7 @@ const MyApp = ({ Component, pageProps }) => { {/* FontawesomeCDN */} + ) } diff --git a/themes/fukasawa/LayoutBase.js b/themes/fukasawa/LayoutBase.js index 479e26b3..b4fb1039 100644 --- a/themes/fukasawa/LayoutBase.js +++ b/themes/fukasawa/LayoutBase.js @@ -1,6 +1,7 @@ import CommonHead from '@/components/CommonHead' import TopNav from './components/TopNav' import AsideLeft from './components/AsideLeft' +import Live2D from '@/components/Live2D' /** * 基础布局 采用左右两侧布局,移动端使用顶部导航栏 @@ -22,11 +23,12 @@ const LayoutBase = (props) => { headerSlot, meta } = props + const leftAreaSlot = return (<>
- +
{headerSlot}
diff --git a/themes/fukasawa/components/AsideLeft.js b/themes/fukasawa/components/AsideLeft.js index 116e5244..17dec9ea 100644 --- a/themes/fukasawa/components/AsideLeft.js +++ b/themes/fukasawa/components/AsideLeft.js @@ -8,7 +8,7 @@ import SiteInfo from './SiteInfo' import Catalog from './Catalog' function AsideLeft (props) { - const { tags, currentTag, categories, currentCategory, post } = props + const { tags, currentTag, categories, currentCategory, post, slot } = props return
@@ -44,8 +44,10 @@ function AsideLeft (props) {
+
+ {slot} +
-
} diff --git a/themes/hexo/LayoutBase.js b/themes/hexo/LayoutBase.js index 43291ef8..7979f625 100644 --- a/themes/hexo/LayoutBase.js +++ b/themes/hexo/LayoutBase.js @@ -7,6 +7,7 @@ import SideRight from './components/SideRight' import TopNav from './components/TopNav' import smoothscroll from 'smoothscroll-polyfill' import FloatDarkModeButton from './components/FloatDarkModeButton' +import Live2D from '@/components/Live2D' /** * 基础布局 采用左右两侧布局,移动端使用顶部导航栏 @@ -18,6 +19,7 @@ const LayoutBase = (props) => { const { children, headerSlot, floatSlot, meta } = props const [show, switchShow] = useState(false) // const [percent, changePercent] = useState(0) // 页面阅读百分比 + const rightAreaSlot = const scrollListener = () => { const targetRef = document.getElementById('wrapper') @@ -49,7 +51,7 @@ const LayoutBase = (props) => {
{children}
- +
diff --git a/themes/hexo/components/SideRight.js b/themes/hexo/components/SideRight.js index 47a391c5..ddddb89d 100644 --- a/themes/hexo/components/SideRight.js +++ b/themes/hexo/components/SideRight.js @@ -8,14 +8,8 @@ import { AnalyticsCard } from './AnalyticsCard' export default function SideRight (props) { const { - post, - currentCategory, - categories, - latestPosts, - tags, - currentTag, - showCategory, - showTag + post, currentCategory, categories, latestPosts, tags, + currentTag, showCategory, showTag, slot } = props return ( @@ -43,11 +37,13 @@ export default function SideRight (props) { } - {post && post.toc && ( - +
+ {post && post.toc && - - )} + } + {slot} +
+
) } diff --git a/themes/medium/LayoutBase.js b/themes/medium/LayoutBase.js index 4a64de32..f3289f85 100644 --- a/themes/medium/LayoutBase.js +++ b/themes/medium/LayoutBase.js @@ -10,6 +10,7 @@ import SearchInput from './components/SearchInput' import BottomMenuBar from './components/BottomMenuBar' import { useGlobal } from '@/lib/global' import { useRouter } from 'next/router' +import Live2D from '@/components/Live2D' /** * 基础布局 采用左右两侧布局,移动端使用顶部导航栏 @@ -40,7 +41,8 @@ const LayoutBase = props => { {/* 桌面端右侧 */}
- +
+ {slotRight}
{router.pathname !== '/search' && } @@ -48,9 +50,15 @@ const LayoutBase = props => { {CONFIG_MEDIUM.WIDGET_REVOLVER_MAPS === 'true' && }
+ +
+
+ +
+ {/* 移动端底部 */}