@@ -45,8 +45,6 @@ import 'prismjs/components/prism-r.js'
45
45
46
46
// 化学方程式
47
47
import '@/lib/mhchem'
48
- // 页面渲染观察者
49
- let observer
50
48
51
49
// https://github.com/txs
52
50
// import PrismMac from '@/components/PrismMac'
@@ -63,10 +61,6 @@ const Modal = dynamic(
63
61
)
64
62
65
63
const NotionPage = ( { post } ) => {
66
- if ( ! post || ! post . blockMap ) {
67
- return < > { post ?. summary || '' } </ >
68
- }
69
-
70
64
const zoom = isBrowser ( ) && mediumZoom ( {
71
65
container : '.notion-viewport' ,
72
66
background : 'rgba(0, 0, 0, 0.2)' ,
@@ -76,10 +70,6 @@ const NotionPage = ({ post }) => {
76
70
77
71
const zoomRef = React . useRef ( zoom ? zoom . clone ( ) : null )
78
72
79
- if ( isBrowser ( ) && ! observer ) {
80
- addWatch4Dom ( )
81
- }
82
-
83
73
React . useEffect ( ( ) => {
84
74
setTimeout ( ( ) => {
85
75
if ( window . location . hash ) {
@@ -109,8 +99,11 @@ const NotionPage = ({ post }) => {
109
99
} , 800 )
110
100
} , [ ] )
111
101
102
+ if ( ! post || ! post . blockMap ) {
103
+ return < > { post ?. summary || '' } </ >
104
+ }
105
+
112
106
return < div id = 'container' className = 'max-w-5xl overflow-x-visible mx-auto' >
113
- < PrismMac />
114
107
< NotionRenderer
115
108
recordMap = { post . blockMap }
116
109
mapPageUrl = { mapPageUrl }
@@ -123,6 +116,9 @@ const NotionPage = ({ post }) => {
123
116
nextImage : Image ,
124
117
nextLink : Link
125
118
} } />
119
+
120
+ < PrismMac />
121
+
126
122
</ div >
127
123
}
128
124
@@ -154,61 +150,4 @@ function getMediumZoomMargin() {
154
150
}
155
151
}
156
152
157
- /**
158
- * 监听DOM变化
159
- * @param {* } element
160
- */
161
- // eslint-disable-next-line no-unused-vars
162
- function addWatch4Dom ( element ) {
163
- // 选择需要观察变动的节点
164
- const targetNode = element || document ?. getElementById ( 'container' )
165
- // 观察器的配置(需要观察什么变动)
166
- const config = {
167
- attributes : true ,
168
- childList : true ,
169
- subtree : true
170
- }
171
-
172
- // 创建一个观察器实例并传入回调函数
173
- observer = new MutationObserver ( mutationCallback )
174
- // console.log('观察节点变化', observer)
175
- // 以上述配置开始观察目标节点
176
- if ( targetNode ) {
177
- observer . observe ( targetNode , config )
178
- }
179
-
180
- // observer.disconnect()
181
- }
182
-
183
- // 当页面发生时会调用此函数
184
- const mutationCallback = ( mutations ) => {
185
- for ( const mutation of mutations ) {
186
- const type = mutation . type
187
- switch ( type ) {
188
- case 'childList' :
189
- // console.log('A child node has been added or removed.', mutation)
190
- if ( mutation . addedNodes . length > 0 ) {
191
- if ( mutation ?. target ?. parentElement ?. nodeName === 'PRE' || mutation ?. target ?. parentElement ?. nodeName === 'CODE' ) {
192
- if ( mutation . addedNodes [ 0 ] . nodeName === '#text' && mutation . target . childElementCount > 0 ) {
193
- mutation . addedNodes [ 0 ] . remove ( ) // 移除新增的内容
194
- }
195
- }
196
- if ( mutation ?. target ?. className === 'language-mermaid' ) {
197
- // mermaid重刷新bug TODO
198
- }
199
- }
200
- break
201
- case 'attributes' :
202
- // console.log(`The ${mutation.attributeName} attribute was modified.`, mutation.target)
203
- // console.log(mutation.attributeName)
204
- break
205
- case 'subtree' :
206
- // console.log('The subtree was modified.', mutation.target)
207
- break
208
- default :
209
- break
210
- }
211
- }
212
- }
213
-
214
153
export default NotionPage
0 commit comments