diff --git a/components/ArticleDetail.js b/components/ArticleDetail.js index bff0cb21..c3188169 100644 --- a/components/ArticleDetail.js +++ b/components/ArticleDetail.js @@ -40,10 +40,10 @@ export default function ArticleDetail ({ post, blockMap, recommendPosts, prev, n return (<>
-
+
{post.type && !post.type.includes('Page') && post?.page_cover && (
{/* Notion文章主体 */} -
+
{blockMap && ( { - if (window) { + if (window && !hasLoad) { initLive2D() + hasLoad = true } }) return
- +
} 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) - } - }) - } - // 加载 waifu.css live2d.min.js waifu-tips.js if (screen.width >= 768) { Promise.all([ @@ -45,3 +26,24 @@ 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) + } + }) +}