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

Commit

Permalink
feat: add client apis
Browse files Browse the repository at this point in the history
email client api instead of out-of-box component
comment client api for customiztion
  • Loading branch information
billyyyyy3320 committed Dec 27, 2019
1 parent e63c026 commit fceda2f
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 51 deletions.
5 changes: 0 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ module.exports = {
"node": true
},

globals: {
COMMENT_SERVICE: true,
IS_NEWSLETTER_ENABLED: true
},

extends: [
'plugin:vue/recommended',
'plugin:prettier/recommended',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@vssue/vuepress-plugin-vssue": "^1.2.0",
"vuejs-paginate": "^2.1.0",
"vuepress-plugin-disqus-comment": "^0.2.3",
"vuepress-plugin-mailchimp": "^1.2.0",
"vuepress-plugin-mailchimp": "^1.3.1",
"vuepress-plugin-sitemap": "^2.3.0"
},
"devDependencies": {
Expand Down
4 changes: 1 addition & 3 deletions src/client/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ import Pagination from './components/Pagination.vue';
import SimplePagination from './components/SimplePagination.vue';
// @ts-ignore
import Comment from './components/Comment.vue';
// @ts-ignore
import Newsletter from './components/Newsletter.vue';

export { Pagination, SimplePagination, Comment, Newsletter };
export { Pagination, SimplePagination, Comment };
18 changes: 5 additions & 13 deletions src/client/components/Comment.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<template>
<Vssue v-if="commentService === 'vssue'" v-bind="vssueProps" />
<vue-disqus v-else-if="commentService === 'disqus'" v-bind="disqusProps" />
<Vssue v-if="$service.comment.service === 'vssue'" v-bind="vssueProps" />
<vue-disqus
v-else-if="$service.comment.service === 'disqus'"
v-bind="disqusProps"
/>
</template>

<script>
Expand Down Expand Up @@ -53,12 +56,6 @@ export default {
},
},
data() {
return {
commentService: COMMENT_SERVICE,
};
},
computed: {
propsWithoutEmptyProperties() {
return pickBy(this.$props, identity);
Expand All @@ -80,10 +77,5 @@ export default {
return Object.assign({ identifier: this.$page.key }, this.commentProps);
},
},
mounted() {
if (typeof COMMENT_SERVICE === 'undefined')
console.warn("There's no comment service!");
},
};
</script>
15 changes: 0 additions & 15 deletions src/client/components/Newsletter.vue

This file was deleted.

13 changes: 13 additions & 0 deletions src/client/services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @ts-ignore
import services from '@dynamic/vuepress_blog/services';

export default ({ Vue }) => {
const computed = {
$service() {
return services;
},
};
Vue.mixin({
computed,
});
};
25 changes: 15 additions & 10 deletions src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => {
* Leverage other plugins
*/
const plugins: any[][] = [];
const services = {
comment: { enabled: false, service: '' },
email: { enabled: false },
};

if (options.sitemap && options.sitemap.hostname) {
const defaultSitemapOptions = { exclude: ['/404.html'] };
Expand All @@ -56,9 +60,13 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => {
switch (commentService) {
case 'vssue':
plugins.push(['@vssue/vuepress-plugin-vssue', commentOptions]);
services.comment.enabled = true;
services.comment.service = commentService;
break;
case 'disqus':
plugins.push(['vuepress-plugin-disqus-comment', commentOptions]);
services.comment.enabled = true;
services.comment.service = commentService;
break;
default:
logger.warn(
Expand All @@ -70,12 +78,9 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => {
}
}

const isNewsletterEnabled = !!(
options.newsletter && options.newsletter.endpoint
);

if (isNewsletterEnabled) {
if (!!(options.newsletter && options.newsletter.endpoint)) {
plugins.push(['vuepress-plugin-mailchimp', options.newsletter]);
services.email.enabled = true;
}

return {
Expand Down Expand Up @@ -240,20 +245,20 @@ export default ${serializePaginations(ctx.serializedPaginations, [
name: `${PREFIX}/pageSorters.js`,
content: `export default ${mapToString(ctx.pageSorters, true)}`,
},
{
name: `${PREFIX}/services.js`,
content: `export default ${JSON.stringify(services, null, 2)}`,
},
];
},

enhanceAppFiles: [
path.resolve(__dirname, '../client/classification.js'),
path.resolve(__dirname, '../client/pagination.js'),
path.resolve(__dirname, '../client/services.js'),
],

plugins,

define: {
COMMENT_SERVICE: options.comment && options.comment.service,
IS_NEWSLETTER_ENABLED: isNewsletterEnabled,
},
};
};

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9852,10 +9852,10 @@ vuepress-plugin-disqus-comment@^0.2.3:
dependencies:
vue-disqus "^3.0.5"

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

0 comments on commit fceda2f

Please sign in to comment.