diff --git a/components/Live2D.js b/components/Live2D.js index 43578793..89e68301 100644 --- a/components/Live2D.js +++ b/components/Live2D.js @@ -5,7 +5,7 @@ import { loadExternalResource } from '@/lib/utils' import { useEffect } from 'react' export default function Live2D() { - if (!BLOG.WIDGET_PET) { + if (!BLOG.WIDGET_PET || !JSON.parse(BLOG.WIDGET_PET)) { return <>> } const { switchTheme } = useGlobal() @@ -29,7 +29,7 @@ function initLive2D() { Promise.all([ // loadExternalResource('https://cdn.zhangxinxu.com/sp/demo/live2d/live2d/js/live2d.js', 'js') loadExternalResource('https://cdn.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/live2d.min.js', 'js') - ]).then(() => { + ]).then((e) => { // https://github.com/xiazeyu/live2d-widget-models loadlive2d('live2d', BLOG.WIDGET_PET_LINK) }) diff --git a/components/NotionPage.js b/components/NotionPage.js index 03b1f1eb..b0c58f5c 100644 --- a/components/NotionPage.js +++ b/components/NotionPage.js @@ -1,65 +1,51 @@ - -import 'prismjs' -import 'prismjs/components/prism-bash' -import 'prismjs/components/prism-javascript' -import 'prismjs/components/prism-markup' -import 'prismjs/components/prism-python' -import 'prismjs/components/prism-typescript' -import 'prismjs/components/prism-java' - import { NotionRenderer } from 'react-notion-x' -import mediumZoom from 'medium-zoom' -import { useEffect, useRef } from 'react' import dynamic from 'next/dynamic' -import { useRouter } from 'next/router' const Code = dynamic(() => - import('react-notion-x/build/third-party/code').then((m) => m.Code) + import('react-notion-x/build/third-party/code').then((m) => m.Code), { ssr: false } ) const Collection = dynamic(() => - import('react-notion-x/build/third-party/collection').then( - (m) => m.Collection - ) + import('react-notion-x/build/third-party/collection').then((m) => m.Collection), { ssr: false } ) + const Equation = dynamic(() => - import('react-notion-x/build/third-party/equation').then((m) => m.Equation) + import('react-notion-x/build/third-party/equation').then((m) => m.Equation), { ssr: false } ) + const Pdf = dynamic( - () => import('react-notion-x/build/third-party/pdf').then((m) => m.Pdf), - { - ssr: false - } + () => import('react-notion-x/build/third-party/pdf').then((m) => m.Pdf), { ssr: false } ) + const Modal = dynamic( - () => import('react-notion-x/build/third-party/modal').then((m) => m.Modal), - { - ssr: false - } + () => import('react-notion-x/build/third-party/modal').then((m) => m.Modal), { ssr: false } ) const NotionPage = ({ post }) => { if (!post || !post.blockMap) { return <>{post?.summary || ''}> } - const zoom = typeof window !== 'undefined' && mediumZoom({ - container: '.notion-viewport', - background: 'rgba(0, 0, 0, 0.2)', - margin: getMediumZoomMargin() - }) - const zoomRef = useRef(zoom ? zoom.clone() : null) - - const router = useRouter() - - useEffect(() => { - // 将所有container下的所有图片添加medium-zoom - const container = document?.getElementById('container') - const imgList = container?.getElementsByTagName('img') - if (imgList && zoomRef.current) { - for (let i = 0; i < imgList.length; i++) { - (zoomRef.current).attach(imgList[i]) - } + setTimeout(() => { + if (typeof document === 'undefined') { + return } - }, [router?.events]) + const buttons = document.getElementsByClassName('notion-code-copy') + for (const e of buttons) { + e.addEventListener('click', fixCopy) + } + }, 500) + + /** + * 复制代码后,会重复 @see https://github.com/tangly1024/NotionNext/issues/165 + * @param {*} e + */ + function fixCopy(e) { + const codeE = e.target.parentElement.parentElement.lastElementChild + console.log(codeE) + const codeEnd = codeE.lastChild + if (codeEnd.nodeName === '#text' && codeE.childNodes.length > 1) { + codeEnd.nodeValue = null + } + } return