From 79b7aa4a370a97de6bb22a842d83b6bbabbfad20 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Fri, 18 Feb 2022 11:06:25 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=B0=81=E8=A3=85loadResources=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/utils.js | 27 +++++++++++++++++++++++++++ themes/NEXT/components/Live2D.js | 22 +--------------------- themes/NEXT/components/Live2DWaifu.js | 22 +--------------------- 3 files changed, 29 insertions(+), 42 deletions(-) create mode 100644 lib/utils.js diff --git a/lib/utils.js b/lib/utils.js new file mode 100644 index 00000000..d3687ab9 --- /dev/null +++ b/lib/utils.js @@ -0,0 +1,27 @@ +// 封装异步加载资源的方法 + +/** + * 加载外部资源 + * @param url 地址 例如 https://xx.com/xx.js + * @param type js 或 css + * @returns {Promise} + */ +export function loadExternalResource (url, type) { + return new Promise((resolve, reject) => { + let tag + + if (type === 'css') { + tag = document.createElement('link') + tag.rel = 'stylesheet' + tag.href = url + } else if (type === 'js') { + tag = document.createElement('script') + tag.src = url + } + if (tag) { + tag.onload = () => resolve(url) + tag.onerror = () => reject(url) + document.head.appendChild(tag) + } + }) +} diff --git a/themes/NEXT/components/Live2D.js b/themes/NEXT/components/Live2D.js index 5ad27c93..c9ce2a1b 100644 --- a/themes/NEXT/components/Live2D.js +++ b/themes/NEXT/components/Live2D.js @@ -1,5 +1,6 @@ /* eslint-disable no-undef */ import CONFIG_NEXT from '../config_next' +import { loadExternalResource } from '@/lib/utils' let hasLoad = false export default function Live2D () { @@ -29,24 +30,3 @@ function initLive2D () { }) } } - -// 封装异步加载资源的方法 -function loadExternalResource (url, type) { - return new Promise((resolve, reject) => { - let tag - - if (type === 'css') { - tag = document.createElement('link') - tag.rel = 'stylesheet' - tag.href = url - } else if (type === 'js') { - tag = document.createElement('script') - tag.src = url - } - if (tag) { - tag.onload = () => resolve(url) - tag.onerror = () => reject(url) - document.head.appendChild(tag) - } - }) -} diff --git a/themes/NEXT/components/Live2DWaifu.js b/themes/NEXT/components/Live2DWaifu.js index e79029ad..060eee4e 100644 --- a/themes/NEXT/components/Live2DWaifu.js +++ b/themes/NEXT/components/Live2DWaifu.js @@ -1,5 +1,6 @@ import Head from 'next/head' import { useEffect } from 'react' +import { loadExternalResource } from '@/lib/utils' export default function Live2DWife () { useEffect(() => { @@ -17,27 +18,6 @@ function initLive2DWife () { const live2dPath = 'https://cdn.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/' // const live2d_path = "/live2d-widget/"; - // 封装异步加载资源的方法 - function loadExternalResource (url, type) { - return new Promise((resolve, reject) => { - let tag - - if (type === 'css') { - tag = document.createElement('link') - tag.rel = 'stylesheet' - tag.href = url - } else if (type === 'js') { - tag = document.createElement('script') - tag.src = url - } - if (tag) { - tag.onload = () => resolve(url) - tag.onerror = () => reject(url) - document.head.appendChild(tag) - } - }) - } - // 加载 waifu.css live2d.min.js waifu-tips.js if (screen.width >= 768) { Promise.all([ From 342c42f42d554b85110f5979226ecc46661d507b Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Fri, 18 Feb 2022 11:06:40 +0800 Subject: [PATCH 2/3] =?UTF-8?q?Tabs=E9=80=BB=E8=BE=91=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Tabs.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/components/Tabs.js b/components/Tabs.js index 66012477..8df76cae 100644 --- a/components/Tabs.js +++ b/components/Tabs.js @@ -41,12 +41,14 @@ const Tabs = ({ children }) => { })} - {children.map((item, index) => { - return
- {item} -
- })} +
+ {children.map((item, index) => { + return
+ {item} +
+ })} +
} From d8c6888920fb20dc65500abca7801b96dca36188 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Fri, 18 Feb 2022 11:06:58 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=BC=95=E5=85=A5React-cusdis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Comment.js | 24 ++++++++++++++---------- components/CommonScript.js | 18 +++++++++--------- components/Cusdis.js | 30 ------------------------------ package.json | 1 + 4 files changed, 24 insertions(+), 49 deletions(-) delete mode 100644 components/Cusdis.js diff --git a/components/Comment.js b/components/Comment.js index a1cc1c04..9b47d752 100644 --- a/components/Comment.js +++ b/components/Comment.js @@ -3,6 +3,8 @@ import dynamic from 'next/dynamic' import { useRouter } from 'next/router' import 'gitalk/dist/gitalk.css' import Tabs from '@/components/Tabs' +import { ReactCusdis } from 'react-cusdis' +import { useGlobal } from '@/lib/global' const GitalkComponent = dynamic( () => { @@ -16,26 +18,29 @@ const UtterancesComponent = dynamic( }, { ssr: false } ) -const CusdisComponent = dynamic( - () => { - return import('@/components/Cusdis') - }, - { ssr: false } -) const Comment = ({ frontMatter }) => { const router = useRouter() + const { locale } = useGlobal() return (
{BLOG.COMMENT_CUSDIS_APP_ID && (
- +
)} {BLOG.COMMENT_UTTERRANCES_REPO && (
-
- )} +
)} {BLOG.COMMENT_GITALK_CLIENT_ID && (
{ }} />
)} - ) diff --git a/components/CommonScript.js b/components/CommonScript.js index c812f920..ae924fbd 100644 --- a/components/CommonScript.js +++ b/components/CommonScript.js @@ -85,12 +85,12 @@ const CommonScript = () => { {/* 谷歌统计 */} {BLOG.ANALYTICS_GOOGLE_ID && (<> -