import { NotionRenderer } from 'react-notion-x' import dynamic from 'next/dynamic' import mediumZoom from 'medium-zoom' import React from 'react' import { isBrowser } from '@/lib/utils' import Image from 'next/image' import Link from 'next/link' import { Code } from 'react-notion-x/build/third-party/code' // 支持更多的自定义语言 import 'prismjs/components/prism-r.js' const Collection = dynamic(() => import('react-notion-x/build/third-party/collection').then((m) => m.Collection), { ssr: true } ) const Equation = dynamic(() => import('react-notion-x/build/third-party/equation').then((m) => m.Equation), { ssr: true } ) const Pdf = dynamic( () => 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 } ) const NotionPage = ({ post }) => { if (!post || !post.blockMap) { return <>{post?.summary || ''}> } const zoom = isBrowser() && mediumZoom({ container: '.notion-viewport', background: 'rgba(0, 0, 0, 0.2)', scrollOffset: 200, margin: getMediumZoomMargin() }) const zoomRef = React.useRef(zoom ? zoom.clone() : null) React.useEffect(() => { setTimeout(() => { if (window.location.hash) { const tocNode = document.getElementById(window.location.hash.substring(1)) if (tocNode && tocNode.className.indexOf('notion') > -1) { tocNode.scrollIntoView({ block: 'start', behavior: 'smooth' }) } } }, 180) setTimeout(() => { if (isBrowser()) { // 将相册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]) } } // 相册中的url替换成可点击 const cards = document.getElementsByClassName('notion-collection-card') for (const e of cards) { e.removeAttribute('href') const links = e.querySelectorAll('.notion-link') if (links && links.length > 0) { for (const l of links) { l.parentElement.innerHTML = `${l.innerText}` } } } } }, 800) addWatch4Dom() }, []) return