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

Commit 84393ce

Browse files
committed
refactor: split code properly
1 parent 236a756 commit 84393ce

File tree

2 files changed

+56
-52
lines changed

2 files changed

+56
-52
lines changed

Diff for: src/node/handleOptions.ts

+53
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,64 @@ export function handleOptions(
187187
});
188188
}
189189

190+
/**
191+
* 3. Leverage other plugins
192+
*/
193+
const plugins: any[][] = [];
194+
const services = {
195+
comment: { enabled: false, service: '' },
196+
email: { enabled: false },
197+
};
198+
199+
if (options.sitemap && options.sitemap.hostname) {
200+
const defaultSitemapOptions = { exclude: ['/404.html'] };
201+
const sitemapOptions = Object.assign(
202+
{},
203+
defaultSitemapOptions,
204+
options.sitemap
205+
);
206+
const sitemapDependencies = [
207+
['vuepress-plugin-sitemap', sitemapOptions],
208+
['@vuepress/last-updated'],
209+
];
210+
plugins.push(...sitemapDependencies);
211+
}
212+
213+
if (options.comment) {
214+
const { service: commentService, ...commentOptions } = options.comment;
215+
switch (commentService) {
216+
case 'vssue':
217+
plugins.push(['@vssue/vuepress-plugin-vssue', commentOptions]);
218+
services.comment.enabled = true;
219+
services.comment.service = commentService;
220+
break;
221+
case 'disqus':
222+
plugins.push(['vuepress-plugin-disqus-comment', commentOptions]);
223+
services.comment.enabled = true;
224+
services.comment.service = commentService;
225+
break;
226+
default:
227+
logger.warn(
228+
`[@vuepress/plugin-blog] Invalid comment service: ${chalk.cyan(
229+
commentService
230+
)}`
231+
);
232+
break;
233+
}
234+
}
235+
236+
if (!!(options.newsletter && options.newsletter.endpoint)) {
237+
plugins.push(['vuepress-plugin-mailchimp', options.newsletter]);
238+
services.email.enabled = true;
239+
}
240+
190241
const processedData = {
191242
pageEnhancers,
192243
frontmatterClassificationPages,
193244
extraPages,
194245
paginations,
246+
plugins,
247+
services,
195248
};
196249

197250
logObject('Handle options', processedData, true);

Diff for: src/node/index.ts

+3-52
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { path, logger, chalk } from '@vuepress/shared-utils';
1+
import { path } from '@vuepress/shared-utils';
22
import { handleOptions } from './handleOptions';
33
import { registerPaginations } from './pagination';
44
import { BlogPluginOptions } from './interface/Options';
@@ -30,59 +30,10 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => {
3030
frontmatterClassificationPages,
3131
extraPages,
3232
paginations,
33+
plugins,
34+
services,
3335
} = handleOptions(options, ctx);
3436

35-
/**
36-
* Leverage other plugins
37-
*/
38-
const plugins: any[][] = [];
39-
const services = {
40-
comment: { enabled: false, service: '' },
41-
email: { enabled: false },
42-
};
43-
44-
if (options.sitemap && options.sitemap.hostname) {
45-
const defaultSitemapOptions = { exclude: ['/404.html'] };
46-
const sitemapOptions = Object.assign(
47-
{},
48-
defaultSitemapOptions,
49-
options.sitemap
50-
);
51-
const sitemapDependencies = [
52-
['vuepress-plugin-sitemap', sitemapOptions],
53-
['@vuepress/last-updated'],
54-
];
55-
plugins.push(...sitemapDependencies);
56-
}
57-
58-
if (options.comment) {
59-
const { service: commentService, ...commentOptions } = options.comment;
60-
switch (commentService) {
61-
case 'vssue':
62-
plugins.push(['@vssue/vuepress-plugin-vssue', commentOptions]);
63-
services.comment.enabled = true;
64-
services.comment.service = commentService;
65-
break;
66-
case 'disqus':
67-
plugins.push(['vuepress-plugin-disqus-comment', commentOptions]);
68-
services.comment.enabled = true;
69-
services.comment.service = commentService;
70-
break;
71-
default:
72-
logger.warn(
73-
`[@vuepress/plugin-blog] Invalid comment service: ${chalk.cyan(
74-
commentService
75-
)}`
76-
);
77-
break;
78-
}
79-
}
80-
81-
if (!!(options.newsletter && options.newsletter.endpoint)) {
82-
plugins.push(['vuepress-plugin-mailchimp', options.newsletter]);
83-
services.email.enabled = true;
84-
}
85-
8637
return {
8738
name: 'vuepress-plugin-blog',
8839

0 commit comments

Comments
 (0)