diff --git a/components/ArticleDetail.js b/components/ArticleDetail.js index 0e91dc34..2a86de3f 100644 --- a/components/ArticleDetail.js +++ b/components/ArticleDetail.js @@ -19,11 +19,12 @@ import 'prismjs/components/prism-javascript' import 'prismjs/components/prism-markup' import 'prismjs/components/prism-python' import 'prismjs/components/prism-typescript' -import { useRef } from 'react' +import { useEffect, useRef } from 'react' import { Code, Collection, CollectionRow, Equation, NotionRenderer } from 'react-notion-x' import ArticleCopyright from './ArticleCopyright' import Live2D from './Live2D' import WordCount from './WordCount' +import mediumZoom from 'medium-zoom' /** * @@ -37,6 +38,19 @@ export default function ArticleDetail ({ post, blockMap, recommendPosts, prev, n const { locale } = useGlobal() const date = formatDate(post?.date?.start_date || post.createdTime, locale.LOCALE) + 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) + function attachZoom (image) { + if (zoomRef.current) { + (zoomRef.current).attach(image) + } + } + const attachZoomRef = attachZoom + return (<>
{post.type && !post.type.includes('Page') && post?.page_cover && ( -
- {post.title} -
+
+ {/* eslint-disable-next-line @next/next/no-img-element */} + {post.title} +
)} + {/* 文章Title */}
{post.title} @@ -176,3 +186,21 @@ export default function ArticleDetail ({ post, blockMap, recommendPosts, prev, n const mapPageUrl = id => { return 'https://www.notion.so/' + id.replace(/-/g, '') } + +function getMediumZoomMargin () { + const width = window.innerWidth + + if (width < 500) { + return 8 + } else if (width < 800) { + return 20 + } else if (width < 1280) { + return 30 + } else if (width < 1600) { + return 40 + } else if (width < 1920) { + return 48 + } else { + return 72 + } +} diff --git a/styles/notion.css b/styles/notion.css index 1efb0d33..c9fcca5c 100644 --- a/styles/notion.css +++ b/styles/notion.css @@ -196,6 +196,8 @@ .medium-zoom-overlay { z-index: 300; + -webkit-backdrop-filter: blur(5px); + backdrop-filter: blur(5px); } .medium-zoom-image {