diff --git a/components/NotionPage.js b/components/NotionPage.js index fe75ff7b..29fe3bed 100644 --- a/components/NotionPage.js +++ b/components/NotionPage.js @@ -21,6 +21,7 @@ const Pdf = dynamic( const Modal = dynamic( () => import('react-notion-x/build/third-party/modal').then((m) => m.Modal), { ssr: false } ) + const NotionPage = ({ post }) => { if (!post || !post.blockMap) { return <>{post?.summary || ''}> @@ -34,41 +35,24 @@ const NotionPage = ({ post }) => { const zoomRef = React.useRef(zoom ? zoom.clone() : null) + React.useEffect(() => { + addWatch4Dom() + }, []) setTimeout(() => { - if (typeof document !== 'undefined') { - const buttons = document.getElementsByClassName('notion-code-copy') - for (const e of buttons) { - e.addEventListener('click', fixCopy) - } - // 将相册gallery下的图片加入放大功能 - // const container = document?.getElementById('container') - const imgList = document?.querySelectorAll('.notion-collection-card-cover img') - if (imgList && zoomRef.current) { - for (let i = 0; i < imgList.length; i++) { - (zoomRef.current).attach(imgList[i]) - } + // 将相册gallery下的图片加入放大功能 + const imgList = document?.querySelectorAll('.notion-collection-card-cover img') + if (imgList && zoomRef.current) { + for (let i = 0; i < imgList.length; i++) { + (zoomRef.current).attach(imgList[i]) } + } - const cards = document.getElementsByClassName('notion-collection-card') - for (const e of cards) { - e.removeAttribute('href') - } + const cards = document?.getElementsByClassName('notion-collection-card') + for (const e of cards) { + e.removeAttribute('href') } }, 800) - /** - * 复制代码后,会重复 @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