vuepress-plugin-twikoo 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Comment.vue +24 -24
- package/index.js +1 -1
- package/package.json +1 -1
package/Comment.vue
CHANGED
|
@@ -8,19 +8,10 @@ export default {
|
|
|
8
8
|
// 检查是否在浏览器环境中
|
|
9
9
|
if (typeof window !== 'undefined') {
|
|
10
10
|
// 如果指定了容器,将评论组件移动到指定位置
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const commentContainer = document.getElementById('tcomment')
|
|
16
|
-
if (commentContainer) {
|
|
17
|
-
targetContainer.appendChild(commentContainer)
|
|
18
|
-
}
|
|
19
|
-
} else {
|
|
20
|
-
console.warn(`Twikoo target container not found: ${TWIKOO_CONTAINER}`)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
this.initTwikoo()
|
|
11
|
+
this.nextTick(() => {
|
|
12
|
+
this.moveContainer()
|
|
13
|
+
this.initTwikoo()
|
|
14
|
+
})
|
|
24
15
|
}
|
|
25
16
|
|
|
26
17
|
this.$router.afterEach((to, from) => {
|
|
@@ -30,15 +21,7 @@ export default {
|
|
|
30
21
|
// 检查是否在浏览器环境中
|
|
31
22
|
if (typeof window !== 'undefined') {
|
|
32
23
|
// 重新定位评论组件
|
|
33
|
-
|
|
34
|
-
const targetContainer = document.querySelector(TWIKOO_CONTAINER)
|
|
35
|
-
if (targetContainer) {
|
|
36
|
-
const commentContainer = document.getElementById('tcomment')
|
|
37
|
-
if (commentContainer && commentContainer.parentNode !== targetContainer) {
|
|
38
|
-
targetContainer.appendChild(commentContainer)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
24
|
+
this.moveContainer()
|
|
42
25
|
this.initTwikoo()
|
|
43
26
|
}
|
|
44
27
|
})
|
|
@@ -58,12 +41,29 @@ export default {
|
|
|
58
41
|
const twikoo = await import('twikoo')
|
|
59
42
|
twikoo.init({
|
|
60
43
|
...TWIKOO_OPTIONS,
|
|
61
|
-
el: '#tcomment'
|
|
44
|
+
el: TWIKOO_OPTIONS.el || '#tcomment'
|
|
62
45
|
})
|
|
63
46
|
},
|
|
47
|
+
|
|
64
48
|
needComment(frontmatter) {
|
|
65
|
-
return frontmatter.
|
|
49
|
+
return frontmatter.twikoo !== false
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
moveContainer() {
|
|
53
|
+
if (TWIKOO_CONTAINER) {
|
|
54
|
+
const targetContainer = document.querySelector(TWIKOO_CONTAINER)
|
|
55
|
+
if (targetContainer) {
|
|
56
|
+
// 将评论容器移动到目标位置
|
|
57
|
+
const tkComments = document.querySelector('.tk-comments')
|
|
58
|
+
const el = tkComments.parentElement
|
|
59
|
+
const commentContainer = el || document.querySelector(TWIKOO_OPTIONS.el)
|
|
60
|
+
if (commentContainer) {
|
|
61
|
+
targetContainer.appendChild(commentContainer)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
66
65
|
}
|
|
66
|
+
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
</script>
|
package/index.js
CHANGED