Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit aea4305

Browse files
committed
feat: integrate comment service
* feat: integrate vssue * feat: integrate Disqus
1 parent fb5e00f commit aea4305

File tree

8 files changed

+197
-5
lines changed

8 files changed

+197
-5
lines changed

docs/config/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,18 @@ It will be enabled when `hostname` is provided. e.g.
203203
}
204204
```
205205
The 404 page is excluded by default. Further options, please head to [vuepress-plugin-sitemap](https://github.com/ekoeryanto/vuepress-plugin-sitemap#options).
206+
207+
## comment
208+
209+
### service
210+
211+
Service to accomplish commenting.
212+
213+
- Type: `'vssue' | 'disqus';`
214+
- Default: `undefined`
215+
- Required: `false`
216+
217+
### others
218+
Other options depend on which service you pick since this feature is accomplished by the plugins below. All options except `service` will be passed directly to the plugin, so take a look at their documentation for more details:
219+
- [vuepress-plugin-disqus-comment](https://vuepress-plugin-disqus.netlify.com/#config)
220+
- [vuepress-plugin-vssue](https://vssue.js.org/guide/vuepress.html#usage)

examples/blog/.vuepress/config.js

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ module.exports = {
4444
},
4545
sitemap: {
4646
hostname: 'https://yourdomain'
47+
},
48+
comment: {
49+
service: 'disqus',
50+
shortname: 'vuepress-plugin-blog'
4751
}
4852
}],
4953
],
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
<template>
2-
<Content/>
2+
<div>
3+
<Content/>
4+
<Comment/>
5+
</div>
36
</template>
7+
8+
<script>
9+
import { Comment } from '../../../../../lib/client/components.js'
10+
11+
export default {
12+
components: { Comment }
13+
}
14+
</script>

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
"author": "ULIVZ <[email protected]>",
3030
"license": "MIT",
3131
"dependencies": {
32+
"@vssue/api-github-v3": "^1.1.2",
33+
"@vssue/vuepress-plugin-vssue": "^1.2.0",
3234
"vuejs-paginate": "^2.1.0",
35+
"vuepress-plugin-disqus-comment": "^0.2.3",
3336
"vuepress-plugin-forked-sitemap": "^0.0.1"
3437
},
3538
"devDependencies": {

src/client/components.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
import Pagination from './components/Pagination.vue'
33
// @ts-ignore
44
import SimplePagination from './components/SimplePagination.vue'
5+
// @ts-ignore
6+
import Comment from './components/Comment.vue'
57

6-
export { Pagination, SimplePagination }
8+
export { Pagination, SimplePagination, Comment }

src/client/components/Comment.vue

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<template>
2+
<Vssue
3+
v-if="commentService === 'vssue'"
4+
v-bind="propsWithoutEmptyProperties"
5+
:title="$page.title"
6+
/>
7+
<vue-disqus
8+
v-else-if="commentService === 'disqus'"
9+
v-bind="propsWithoutEmptyProperties"
10+
:identifier="$page.key"
11+
/>
12+
</template>
13+
14+
<script>
15+
import identity from 'lodash/identity'
16+
import pickBy from 'lodash/pickBy'
17+
18+
export default {
19+
props: {
20+
// vssue's props
21+
title: {
22+
type: String | Function,
23+
required: false
24+
},
25+
issueId: {
26+
type: String | Number,
27+
required: false
28+
},
29+
options: {
30+
type: Object,
31+
required: false
32+
},
33+
// vue-disqus's props
34+
shortname: {
35+
type: String,
36+
required: false
37+
},
38+
identifier: {
39+
type: String,
40+
required: false
41+
},
42+
url: {
43+
type: String,
44+
required: false
45+
},
46+
title: {
47+
type: String,
48+
required: false
49+
},
50+
remote_auth_s3: {
51+
type: String,
52+
required: false
53+
},
54+
api_key: {
55+
type: String,
56+
required: false
57+
},
58+
sso_config: {
59+
type: Object,
60+
required: false
61+
},
62+
language: {
63+
type: String,
64+
required: false
65+
}
66+
},
67+
68+
data () {
69+
return {
70+
commentService: COMMENT_SERVICE
71+
}
72+
},
73+
74+
computed: {
75+
propsWithoutEmptyProperties () {
76+
return pickBy(this.$props, identity);
77+
}
78+
},
79+
80+
mounted () {
81+
if (typeof COMMENT_SERVICE === 'undefined') console.warn("There's no comment service!")
82+
},
83+
}
84+
</script>
85+

src/node/index.ts

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as path from 'path'
1+
import { path, logger, chalk, } from '@vuepress/shared-utils'
22
import { handleOptions } from './handleOptions'
33
import { registerPaginations } from './pagination'
44
import { BlogPluginOptions } from './interface/Options'
@@ -45,6 +45,23 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => {
4545
plugins.push(...sitemapDependencies)
4646
}
4747

48+
if (options.comment) {
49+
const { service: commentService, ...commentOptions } = options.comment
50+
switch (commentService) {
51+
case 'vssue':
52+
plugins.push(['@vssue/vuepress-plugin-vssue', commentOptions])
53+
break;
54+
case 'disqus':
55+
plugins.push(['vuepress-plugin-disqus-comment', commentOptions])
56+
break;
57+
default:
58+
logger.warn(
59+
`[@vuepress/plugin-blog] Invalid comment service: ${chalk.cyan(commentService)}`
60+
)
61+
break;
62+
}
63+
}
64+
4865
return {
4966
name: 'vuepress-plugin-blog',
5067

@@ -209,7 +226,11 @@ export default ${serializePaginations(ctx.serializedPaginations, [
209226
path.resolve(__dirname, '../client/pagination.js'),
210227
],
211228

212-
plugins
229+
plugins,
230+
231+
define: {
232+
COMMENT_SERVICE: options.comment && options.comment.service
233+
}
213234
}
214235
}
215236

src/node/interface/Options.ts

+52-1
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,63 @@ export interface FrontmatterClassifier {
7777
pagination?: PaginationConfig;
7878
}
7979

80+
/**
81+
* Comment configuration
82+
*/
83+
84+
/**
85+
* Vssue configuration
86+
* For details, head Vssue documentation: https://vssue.js.org/
87+
*/
88+
export interface VssueOptions {
89+
platform: 'github' | 'github-v4' | 'gitlab' | 'bitbucket' | 'gitee';
90+
owner: string;
91+
repo: string;
92+
clientId: string;
93+
clientSecret: string;
94+
baseURL: string;
95+
state: string;
96+
labels: Array<string>;
97+
prefix: string;
98+
admins: Array<string>;
99+
perPage: number;
100+
locale: string;
101+
proxy: string | ((url: string) => string);
102+
issueContent: ((param: { options: VssueOptions, url: string }) => string | Promise<string>);
103+
autoCreateIssue: boolean;
104+
}
105+
106+
/**
107+
* Disqus configuration
108+
* For details, head vue-disqus documentation: https://github.com/ktquez/vue-disqus#props
109+
*/
110+
export interface DisqusOptions {
111+
shortname: string;
112+
identifier: string;
113+
url: string;
114+
title: string;
115+
remote_auth_s3: string;
116+
api_key: string;
117+
sso_config: any;
118+
language: string;
119+
}
120+
121+
export interface Comment extends Partial<VssueOptions>, Partial<DisqusOptions> {
122+
/**
123+
* The comment service
124+
*/
125+
service: 'vssue' | 'disqus';
126+
}
127+
128+
80129
/**
81130
* Options for this plugin.
82131
*/
83132
export interface BlogPluginOptions {
84133
directories: DirectoryClassifier[];
85134
frontmatters: FrontmatterClassifier[];
86135
globalPagination: PaginationConfig;
87-
sitemap:any
136+
//TODO: define types
137+
sitemap: any;
138+
comment: Comment;
88139
}

0 commit comments

Comments
 (0)