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

Commit fceda2f

Browse files
committed
feat: add client apis
email client api instead of out-of-box component comment client api for customiztion
1 parent e63c026 commit fceda2f

File tree

8 files changed

+39
-51
lines changed

8 files changed

+39
-51
lines changed

Diff for: .eslintrc.js

-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ module.exports = {
88
"node": true
99
},
1010

11-
globals: {
12-
COMMENT_SERVICE: true,
13-
IS_NEWSLETTER_ENABLED: true
14-
},
15-
1611
extends: [
1712
'plugin:vue/recommended',
1813
'plugin:prettier/recommended',

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"@vssue/vuepress-plugin-vssue": "^1.2.0",
5656
"vuejs-paginate": "^2.1.0",
5757
"vuepress-plugin-disqus-comment": "^0.2.3",
58-
"vuepress-plugin-mailchimp": "^1.2.0",
58+
"vuepress-plugin-mailchimp": "^1.3.1",
5959
"vuepress-plugin-sitemap": "^2.3.0"
6060
},
6161
"devDependencies": {

Diff for: src/client/components.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ import Pagination from './components/Pagination.vue';
44
import SimplePagination from './components/SimplePagination.vue';
55
// @ts-ignore
66
import Comment from './components/Comment.vue';
7-
// @ts-ignore
8-
import Newsletter from './components/Newsletter.vue';
97

10-
export { Pagination, SimplePagination, Comment, Newsletter };
8+
export { Pagination, SimplePagination, Comment };

Diff for: src/client/components/Comment.vue

+5-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<template>
2-
<Vssue v-if="commentService === 'vssue'" v-bind="vssueProps" />
3-
<vue-disqus v-else-if="commentService === 'disqus'" v-bind="disqusProps" />
2+
<Vssue v-if="$service.comment.service === 'vssue'" v-bind="vssueProps" />
3+
<vue-disqus
4+
v-else-if="$service.comment.service === 'disqus'"
5+
v-bind="disqusProps"
6+
/>
47
</template>
58

69
<script>
@@ -53,12 +56,6 @@ export default {
5356
},
5457
},
5558
56-
data() {
57-
return {
58-
commentService: COMMENT_SERVICE,
59-
};
60-
},
61-
6259
computed: {
6360
propsWithoutEmptyProperties() {
6461
return pickBy(this.$props, identity);
@@ -80,10 +77,5 @@ export default {
8077
return Object.assign({ identifier: this.$page.key }, this.commentProps);
8178
},
8279
},
83-
84-
mounted() {
85-
if (typeof COMMENT_SERVICE === 'undefined')
86-
console.warn("There's no comment service!");
87-
},
8880
};
8981
</script>

Diff for: src/client/components/Newsletter.vue

-15
This file was deleted.

Diff for: src/client/services.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @ts-ignore
2+
import services from '@dynamic/vuepress_blog/services';
3+
4+
export default ({ Vue }) => {
5+
const computed = {
6+
$service() {
7+
return services;
8+
},
9+
};
10+
Vue.mixin({
11+
computed,
12+
});
13+
};

Diff for: src/node/index.ts

+15-10
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => {
3636
* Leverage other plugins
3737
*/
3838
const plugins: any[][] = [];
39+
const services = {
40+
comment: { enabled: false, service: '' },
41+
email: { enabled: false },
42+
};
3943

4044
if (options.sitemap && options.sitemap.hostname) {
4145
const defaultSitemapOptions = { exclude: ['/404.html'] };
@@ -56,9 +60,13 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => {
5660
switch (commentService) {
5761
case 'vssue':
5862
plugins.push(['@vssue/vuepress-plugin-vssue', commentOptions]);
63+
services.comment.enabled = true;
64+
services.comment.service = commentService;
5965
break;
6066
case 'disqus':
6167
plugins.push(['vuepress-plugin-disqus-comment', commentOptions]);
68+
services.comment.enabled = true;
69+
services.comment.service = commentService;
6270
break;
6371
default:
6472
logger.warn(
@@ -70,12 +78,9 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => {
7078
}
7179
}
7280

73-
const isNewsletterEnabled = !!(
74-
options.newsletter && options.newsletter.endpoint
75-
);
76-
77-
if (isNewsletterEnabled) {
81+
if (!!(options.newsletter && options.newsletter.endpoint)) {
7882
plugins.push(['vuepress-plugin-mailchimp', options.newsletter]);
83+
services.email.enabled = true;
7984
}
8085

8186
return {
@@ -240,20 +245,20 @@ export default ${serializePaginations(ctx.serializedPaginations, [
240245
name: `${PREFIX}/pageSorters.js`,
241246
content: `export default ${mapToString(ctx.pageSorters, true)}`,
242247
},
248+
{
249+
name: `${PREFIX}/services.js`,
250+
content: `export default ${JSON.stringify(services, null, 2)}`,
251+
},
243252
];
244253
},
245254

246255
enhanceAppFiles: [
247256
path.resolve(__dirname, '../client/classification.js'),
248257
path.resolve(__dirname, '../client/pagination.js'),
258+
path.resolve(__dirname, '../client/services.js'),
249259
],
250260

251261
plugins,
252-
253-
define: {
254-
COMMENT_SERVICE: options.comment && options.comment.service,
255-
IS_NEWSLETTER_ENABLED: isNewsletterEnabled,
256-
},
257262
};
258263
};
259264

Diff for: yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -9852,10 +9852,10 @@ vuepress-plugin-disqus-comment@^0.2.3:
98529852
dependencies:
98539853
vue-disqus "^3.0.5"
98549854

9855-
vuepress-plugin-mailchimp@^1.2.0:
9856-
version "1.2.0"
9857-
resolved "https://registry.yarnpkg.com/vuepress-plugin-mailchimp/-/vuepress-plugin-mailchimp-1.2.0.tgz#674ff69e94fc6b780920787685f40e2867ceb5cd"
9858-
integrity sha512-MI3hZnI8UmuVJppbnGQjUwcv5Ylx73SO3n9jt+7MFR///SEU8Dx6BHVYMLKPPMYHcIFuJstvDgsYvhCkP155vg==
9855+
vuepress-plugin-mailchimp@^1.3.1:
9856+
version "1.3.1"
9857+
resolved "https://registry.yarnpkg.com/vuepress-plugin-mailchimp/-/vuepress-plugin-mailchimp-1.3.1.tgz#c2001d4b5dc526617094d834cba8c961d5792a40"
9858+
integrity sha512-oyS2DrM5Wnr2/dYoGEig/IQff+vRtt7YXj/yRWDMy+fu/yscdwVvkLjBwVsJBeqDx+GWL4pXQtHY3majHIwH8g==
98599859
dependencies:
98609860
jsonp "^0.2.1"
98619861
query-string "^6.9.0"

0 commit comments

Comments
 (0)