Skip to content

Commit 82837e5

Browse files
committed
add Waline support
1 parent bb57505 commit 82837e5

File tree

4 files changed

+83
-28
lines changed

4 files changed

+83
-28
lines changed

Comment.vue

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
<script>
66
import {
77
provider,
8-
renderConfig,
9-
loadScript,
108
} from './util'
119
1210
const commentDomID = 'vuepress-plugin-comment'
@@ -41,16 +39,19 @@ export default {
4139
* Clear last page comment dom
4240
*/
4341
function clear (frontmatter) {
42+
let el = COMMENT_OPTIONS.el || commentDomID
43+
if (el.startsWith('#')) {
44+
el = el.slice(1)
45+
}
4446
switch (COMMENT_CHOOSEN) {
4547
case 'gitalk':
4648
return provider.gitalk.clear(commentDomID)
4749
case 'valine':
48-
let el = COMMENT_OPTIONS.el || commentDomID
49-
if (el.startsWith('#')) {
50-
el = el.slice(1)
51-
}
5250
console.log(el)
5351
return provider.valine.clear(el)
52+
case 'waline':
53+
console.log(el)
54+
return provider.waline.clear(el)
5455
default: return false
5556
}
5657
}
@@ -74,15 +75,17 @@ function renderComment (frontmatter) {
7475
return
7576
}
7677
78+
let el = COMMENT_OPTIONS.el || commentDomID
79+
if (el.startsWith('#')) {
80+
el = el.slice(1)
81+
}
7782
switch (COMMENT_CHOOSEN) {
7883
case 'gitalk':
7984
return provider.gitalk.render(frontmatter, commentDomID)
8085
case 'valine':
81-
let el = COMMENT_OPTIONS.el || commentDomID
82-
if (el.startsWith('#')) {
83-
el = el.slice(1)
84-
}
8586
return provider.valine.render(frontmatter, el)
87+
case 'waline':
88+
return provider.waline.render(frontmatter, el)
8689
default: return false
8790
}
8891
}

README.md

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Vuepress-comment-plugin
1+
# Vuepress-comment-plugin-plus
22

33
[![](https://img.shields.io/badge/online-preview-faad14.svg?style=popout-square)](https://xin-tan.com/)
44
[![](https://img.shields.io/npm/dm/vuepress-plugin-comment.svg?style=flat-square)](https://www.npmjs.com/package/vuepress-plugin-comment)
@@ -15,12 +15,14 @@
1515
- [⚠️Route object properties](#⚠️Route-object-properties)
1616
- [Use with Gitalk](#use-in-gitalk)
1717
- [Use with Valine](#use-in-valine)
18+
- [Use with Waline](#use-in-waline)
1819
- [Hide comment](#how-to-hide-page-comment)
1920
- [Options detail](#options-detail)
2021
- [Todo](#todo)
2122

2223
## Features
2324

25+
- Support Waline
2426
- Support Gitalk, Valine
2527
- Dynamic Import
2628
- Response router change and refresh automatic
@@ -33,19 +35,19 @@
3335
With `npm`:
3436

3537
```bash
36-
npm install --save vuepress-plugin-comment
38+
npm install --save vuepress-plugin-comment-plus
3739
```
3840

3941
With `yarn`:
4042

4143
```bash
42-
yarn add vuepress-plugin-comment -D
44+
yarn add vuepress-plugin-comment-plus -D
4345
```
4446

4547
With `cnpm`:
4648

4749
```bash
48-
cnpm i --save vuepress-plugin-comment
50+
cnpm i --save vuepress-plugin-comment-plus
4951
```
5052

5153

@@ -55,6 +57,30 @@ cnpm i --save vuepress-plugin-comment
5557

5658
Plugin has registered correct route information in `frontmatter.to` object and `frontmatter.from` object. Their properties are the same as [vue-router's route object](https://router.vuejs.org/api/#route-object-properties).
5759

60+
### Use in Waline
61+
62+
The `options` is exactly the same as `Valine` configuration.
63+
64+
```javascript
65+
module.exports = {
66+
plugins: [
67+
[
68+
'vuepress-plugin-comment-plus',
69+
{
70+
choosen: 'waline',
71+
// options选项中的所有参数,会传给Waline的配置
72+
options: {
73+
el: '#valine-vuepress-comment',
74+
serverURL: 'https://waline-api-green.vercel.app',
75+
path: '<%- frontmatter.commentid || frontmatter.permalink %>'
76+
}
77+
}
78+
]
79+
]
80+
}
81+
```
82+
83+
5884
### Use in Gitalk
5985

6086
The `options` is exactly the same as `Gitalk` configuration.
@@ -63,7 +89,7 @@ The `options` is exactly the same as `Gitalk` configuration.
6389
module.exports = {
6490
plugins: [
6591
[
66-
'vuepress-plugin-comment',
92+
'vuepress-plugin-comment-plus',
6793
{
6894
choosen: 'gitalk',
6995
options: {
@@ -86,7 +112,7 @@ If you want to access variables, such as `$frontmatter` and `window`, please use
86112
module.exports = {
87113
plugins: [
88114
[
89-
'vuepress-plugin-comment',
115+
'vuepress-plugin-comment-plus',
90116
{
91117
choosen: 'gitalk',
92118
options: {
@@ -110,13 +136,13 @@ module.exports = {
110136

111137
### Use in Valine
112138

113-
The `options` is exactly the same as `Valine` configuration.
139+
The `options` is exactly the same as `Waline` configuration.
114140

115141
```javascript
116142
module.exports = {
117143
plugins: [
118144
[
119-
'vuepress-plugin-comment',
145+
'vuepress-plugin-comment-plus',
120146
{
121147
choosen: 'valine',
122148
options: {
@@ -136,7 +162,7 @@ If you want to access variables, such as `$frontmatter` and `window`, please use
136162
module.exports = {
137163
plugins: [
138164
[
139-
'vuepress-plugin-comment',
165+
'vuepress-plugin-comment-plus',
140166
{
141167
choosen: 'valine',
142168
options: {
@@ -151,6 +177,7 @@ module.exports = {
151177
}
152178
```
153179

180+
154181
### How to hide page comment
155182

156183
If you want to hide comment plugin in specified page, set `$frontmatter.comment` or `$frontmatter.comments` to `false`.

package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "vuepress-plugin-comment",
2+
"name": "vuepress-plugin-comment-plus",
33
"version": "0.7.3",
44
"description": "Comment plugin in vuepress, such as Gitalk, Valine...",
55
"main": "index.js",
@@ -8,28 +8,30 @@
88
},
99
"repository": {
1010
"type": "git",
11-
"url": "git+ssh://[email protected]/dongyuanxin/vuepress-plugin-comment.git"
11+
"url": "git+ssh://[email protected]/SivanLaai/vuepress-plugin-comment-plus.git"
1212
},
1313
"keywords": [
1414
"vuepress",
1515
"comment",
1616
"plugin",
1717
"vue",
1818
"gitalk",
19-
"valine"
19+
"valine",
20+
"@waline/client"
2021
],
2122
"author": "dongyuanxin",
2223
"license": "MIT",
2324
"bugs": {
24-
"url": "https://github.com/dongyuanxin/vuepress-plugin-comment/issues"
25+
"url": "https://github.com/SivanLaai/vuepress-plugin-comment-plus/issues"
2526
},
26-
"homepage": "https://github.com/dongyuanxin/vuepress-plugin-comment#readme",
27+
"homepage": "https://github.com/SivanLaai/vuepress-plugin-comment-plus#readme",
2728
"dependencies": {
2829
"ejs": "^2.6.1",
2930
"gitalk": "^1.5.0",
3031
"gitalk-fix": "^1.5.2",
3132
"i": "^0.3.6",
3233
"npm": "^6.9.0",
33-
"valine": "^1.3.9"
34+
"valine": "^1.3.9",
35+
"@waline/client": "^1.3.3"
3436
}
3537
}

util.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ejs from 'ejs'
22

33
import config from './package.json'
44

5-
let Gitalk, Valine
5+
let Gitalk, Valine, Waline
66
loadScript(COMMENT_CHOOSEN)
77

88
const defaultChoosen = 'comment plugins'
@@ -24,6 +24,9 @@ export function loadScript (name) {
2424
import('gitalk/dist/gitalk.css')
2525
.then(() => import('gitalk'))
2626
.then(pkg => Gitalk = pkg.default)
27+
} else if (name === 'waline') {
28+
import('@waline/client')
29+
.then(pkg => Waline = pkg.default)
2730
}
2831
}
2932

@@ -50,7 +53,6 @@ export function renderConfig (config, data) {
5053
result[key] = config[key]
5154
}
5255
})
53-
5456
return result
5557
}
5658

@@ -97,5 +99,26 @@ export const provider = {
9799
}
98100
return true
99101
}
102+
},
103+
waline: {
104+
render (frontmatter, commentDomID) {
105+
const commentDOM = document.createElement('div')
106+
commentDOM.id = commentDomID
107+
108+
const parentDOM = document.querySelector(COMMENT_CONTAINER)
109+
parentDOM.appendChild(commentDOM)
110+
111+
new Waline({
112+
...renderConfig(COMMENT_OPTIONS, { frontmatter }),
113+
el: `#${commentDomID}`
114+
})
115+
},
116+
clear (commentDomID) {
117+
const last = document.querySelector(`#${commentDomID}`)
118+
if (last) {
119+
last.remove()
120+
}
121+
return true
122+
}
100123
}
101-
}
124+
}

0 commit comments

Comments
 (0)