vuepress-plugin-twikoo 1.0.0
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 +46 -0
- package/README.md +76 -0
- package/comment.js +5 -0
- package/index.js +12 -0
- package/package.json +30 -0
package/Comment.vue
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div id="tcomment"></div>
|
|
3
|
+
</template>
|
|
4
|
+
|
|
5
|
+
<script>
|
|
6
|
+
export default {
|
|
7
|
+
mounted () {
|
|
8
|
+
// 检查是否在浏览器环境中
|
|
9
|
+
if (typeof window !== 'undefined') {
|
|
10
|
+
this.initTwikoo()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
this.$router.afterEach((to, from) => {
|
|
14
|
+
if (to && from && to.path === from.path) {
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
// 检查是否在浏览器环境中
|
|
18
|
+
if (typeof window !== 'undefined') {
|
|
19
|
+
this.initTwikoo()
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
},
|
|
23
|
+
methods: {
|
|
24
|
+
async initTwikoo () {
|
|
25
|
+
const frontmatter = {
|
|
26
|
+
to: {},
|
|
27
|
+
from: {},
|
|
28
|
+
...this.$frontmatter
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!this.needComment(frontmatter)) {
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const twikoo = await import('twikoo')
|
|
36
|
+
twikoo.init({
|
|
37
|
+
...TWIKOO_OPTIONS,
|
|
38
|
+
el: '#tcomment'
|
|
39
|
+
})
|
|
40
|
+
},
|
|
41
|
+
needComment (frontmatter) {
|
|
42
|
+
return frontmatter.comment !== false && frontmatter.comments !== false
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
</script>
|
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Vuepress-plugin-twikoo
|
|
2
|
+
|
|
3
|
+
[](https://xin-tan.com/)
|
|
4
|
+
[](https://www.npmjs.com/package/vuepress-plugin-twikoo)
|
|
5
|
+
[](https://vuepress.vuejs.org/)
|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
> Vuepress 1.x 的 Twikoo 评论插件
|
|
10
|
+
|
|
11
|
+
## 特性
|
|
12
|
+
|
|
13
|
+
- 支持 Twikoo 评论系统
|
|
14
|
+
- 动态导入 Twikoo 库,减少初始加载时间
|
|
15
|
+
- 响应路由变化,自动刷新评论
|
|
16
|
+
- 支持使用页面的 `$frontmatter` 配置
|
|
17
|
+
- 通过检查 window 对象避免 SSR 错误
|
|
18
|
+
|
|
19
|
+
## 安装
|
|
20
|
+
|
|
21
|
+
使用 `npm`:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install --save vuepress-plugin-twikoo
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
使用 `yarn`:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
yarn add vuepress-plugin-twikoo -D
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 使用方法
|
|
34
|
+
|
|
35
|
+
在 `config.js` 中配置:
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
module.exports = {
|
|
39
|
+
plugins: [
|
|
40
|
+
[
|
|
41
|
+
'vuepress-plugin-twikoo',
|
|
42
|
+
{
|
|
43
|
+
options: {
|
|
44
|
+
envId: '您的环境 ID',
|
|
45
|
+
// 其他 Twikoo 配置选项
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## 如何在指定页面隐藏评论
|
|
54
|
+
|
|
55
|
+
如果您想在指定页面隐藏评论插件,请在页面的 frontmatter 中设置 `comment` 或 `comments` 为 `false`。
|
|
56
|
+
|
|
57
|
+
例如:
|
|
58
|
+
|
|
59
|
+
```yml
|
|
60
|
+
---
|
|
61
|
+
comment: false
|
|
62
|
+
# comments: false
|
|
63
|
+
---
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
这样,该页面就不会显示评论了。
|
|
67
|
+
|
|
68
|
+
## 配置选项
|
|
69
|
+
|
|
70
|
+
- **options** `object`
|
|
71
|
+
|
|
72
|
+
**必填**。Twikoo 评论插件的配置选项,与 Twikoo 官方配置一致。
|
|
73
|
+
|
|
74
|
+
- **container** `string`
|
|
75
|
+
|
|
76
|
+
**可选,默认为 `'main.page'`**。包含 Twikoo 评论插件的 DOM 选择器。
|
package/comment.js
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
|
|
3
|
+
module.exports = (opts, ctx) => {
|
|
4
|
+
return {
|
|
5
|
+
define: {
|
|
6
|
+
TWIKOO_OPTIONS: opts.options || {},
|
|
7
|
+
TWIKOO_CONTAINER: opts.container || 'main.page'
|
|
8
|
+
},
|
|
9
|
+
enhanceAppFiles: path.resolve(__dirname, 'comment.js'),
|
|
10
|
+
globalUIComponents: 'Comment'
|
|
11
|
+
}
|
|
12
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vuepress-plugin-twikoo",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Twikoo comment plugin for vuepress 1.x",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+ssh://git@github.com/liyao52033/vuepress-plugins.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"vuepress",
|
|
15
|
+
"comment",
|
|
16
|
+
"plugin",
|
|
17
|
+
"vue",
|
|
18
|
+
"twikoo"
|
|
19
|
+
],
|
|
20
|
+
"author": "liyao52033",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/liyao52033/vuepress-plugins/issues"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/liyao52033/vuepress-plugins/tree/main/vuepress-plugin-twikoo",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"ejs": "^4.0.1",
|
|
28
|
+
"twikoo": "^1.6.44"
|
|
29
|
+
}
|
|
30
|
+
}
|