Skip to content

Commit aa6b39e

Browse files
committed
fix: 修复 blog 的配置结构
1 parent 2d619dc commit aa6b39e

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

theme/index.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,13 @@ module.exports = (options, ctx) => {
66
const defaultTheme = require('@vuepress/theme-default');
77
const defaultThemeConfig = defaultTheme(options, ctx);
88

9-
const siteConfig = ctx.siteConfig || {};
109
const themeConfig = ctx.themeConfig = ctx.themeConfig || {};
11-
const type = siteConfig.type || themeConfig.type || 'doc';
1210

1311
const vuepressDir = ctx.vuepressDir;
1412
const iconsDir = path.resolve(vuepressDir, 'public', 'icons');
1513
const iconsLibDir = path.resolve(__dirname, 'icons');
1614
const svgIconsDir = themeConfig.svgIconsDir && path.resolve(vuepressDir, themeConfig.svgIconsDir) || iconsLibDir;
1715

18-
// blog config
19-
const blogPlugin = require('./plugins/blog');
20-
themeConfig.blogConfig = blogPlugin.initBlogConfig(ctx);
21-
2216
const finalConfig = {
2317
define: {
2418
THEME_BUILD_DATE: moment().format('llll'),
@@ -107,7 +101,6 @@ module.exports = (options, ctx) => {
107101
},
108102
plugins: [
109103
...require('./plugins/register')(ctx),
110-
...(type === 'blog' ? blogPlugin.registerPlugins(ctx) : []),
111104
],
112105

113106
// Blog https://github.com/meteorlxy/vuepress-theme-meteorlxy/blob/master/lib/plugins/blog/index.js
@@ -116,9 +109,6 @@ module.exports = (options, ctx) => {
116109
// if (!strippedContent) {
117110
// return;
118111
// }
119-
if (type === 'blog') {
120-
blogPlugin.extendPageData($page, ctx);
121-
}
122112
},
123113
};
124114

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
export default ({ router }) => {
3+
// console.warn('blog...', router);
4+
};

theme/plugins/blog/index.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
const path = require('path');
2+
13
// 初始化默认值
2-
exports.initBlogConfig = require('./init');
4+
const initBlogConfig = require('./init');
35

4-
exports.extendPageData = require('./extendPageData');
6+
const extendPageData = require('./extendPageData');
57

68
// blog plugin
7-
exports.registerPlugins = function(ctx) {
9+
const registerPlugins = function(ctx) {
810
const themeConfig = ctx.themeConfig;
911
const blogConfig = themeConfig.blogConfig;
1012

@@ -22,3 +24,26 @@ exports.registerPlugins = function(ctx) {
2224

2325
return plugins;
2426
};
27+
28+
module.exports = (optins = {}, ctx) => {
29+
const themeConfig = ctx.themeConfig;
30+
// blog config
31+
themeConfig.blogConfig = initBlogConfig(ctx);
32+
33+
console.warn(ctx.addPage);
34+
35+
return {
36+
name: 'blog',
37+
38+
enhanceAppFiles: path.resolve(__dirname, 'enhanceAppFile.js'),
39+
40+
plugins: [
41+
...registerPlugins(ctx),
42+
],
43+
44+
// Blog https://github.com/meteorlxy/vuepress-theme-meteorlxy/blob/master/lib/plugins/blog/index.js
45+
extendPageData($page) {
46+
return extendPageData($page, ctx);
47+
},
48+
};
49+
};

theme/plugins/register.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ function registerPlugins(ctx) {
4242
const siteConfig = ctx.siteConfig || {};
4343
const isLocales = !!siteConfig.locales || !!themeConfig.locales || false;
4444

45+
const type = siteConfig.type || themeConfig.type || 'doc';
46+
if (type === 'blog') {
47+
plugins.push([ require('./blog'), true ]);
48+
}
49+
4550
// pwa
4651
if (themeConfig.pwa) {
4752
plugins.push([

0 commit comments

Comments
 (0)