-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
155 lines (145 loc) · 3.98 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/**
* 这个属于配置文件编译时才会执行
*/
const path = require('path')
const { logger } = require('@vuepress/shared-utils')
const markdownItCenterText = require('markdown-it-center-text')
module.exports = (opts, ctx) => {
/**
* opts ----> config.js里面的themeConfig
* ctx ----> 当前页面所有状态的 Context API
*/
// set default theme config
Object.assign(opts, Object.assign({
lang: 'en-US',
personalInfo: {},
defaultPages: {},
header: {},
footer: {},
infoCard: {},
plugins: {},
pagination: {
perPage: 5,
},
comments: {},
}, opts))
// resolve theme language
if (typeof opts.lang === 'string') {
try {
// 可以监听是否有此文件
require.resolve(`./langs/${opts.lang}`)
} catch (e) {
opts.lang = 'en-US'
logger.warn(`[vuepress-theme-meteorlxy] lang '${opts.lang}' is not available, fallback to 'en-US'`)
}
opts.lang = require(`./langs/${opts.lang}`)
}
console.log(opts, 'opts')
const { comments, lang, defaultPages, header, infoCard } = opts
const noopGeo = (
header.background && (
header.background.url || header.background.useGeo === false
)
) && (
infoCard.headerBackground && (
infoCard.headerBackground.url || infoCard.headerBackground.useGeo === false
)
)
const options = {
name: 'vuepress-theme-meteorlxy',
plugins: [
[require('./plugins/blog'), { lang }],
['@vuepress/plugin-back-to-top'],
['vuepress-plugin-container', { type: 'tip' }],
['vuepress-plugin-container', { type: 'warning' }],
['vuepress-plugin-container', { type: 'danger' }],
['vuepress-plugin-nprogress'],
['vuepress-plugin-redirect'],
['vuepress-plugin-serve'],
['vuepress-plugin-smooth-scroll', opts.plugins['smooth-scroll'] || {}],
['vuepress-plugin-table-of-contents'],
[
'vuepress-plugin-zooming',
Object.assign({
selector: '.content img',
}, opts.plugins.zooming || {}),
],
[
'@vssue/vuepress-plugin-vssue',
comments !== false
? Object.assign({
platform: 'github',
}, comments)
: false,
],
],
globalUIComponents: 'Iconfont',
enhanceAppFiles: [
path.resolve(__dirname, 'enhanceApp.js'),
],
extendMarkdown: md => md.use(markdownItCenterText),
chainWebpack (config, isServer) {
if (noopGeo) {
// point geopattern to noopModule
config
.resolve
.alias
.set('geopattern', path.resolve(__dirname, 'utils/noopModule'))
} else {
// to make geopattern work
if (isServer === false) {
config.node.set('Buffer', false)
}
}
// to use jsx syntax with evergreen config
if (ctx.siteConfig.evergreen) {
config.module
.rule('js')
.test(/\.js$/)
.exclude.add(filePath => {
if (filePath.startsWith(path.resolve(__dirname))) {
return false
}
return true
}).end()
.use('cache-loader')
.loader('cache-loader')
.options({
cacheDirectory: ctx.cacheDirectory,
cacheIdentifier: ctx.cacheIdentifier,
})
.end()
.use('babel-loader')
.loader('babel-loader')
.options({
babelrc: false,
configFile: false,
presets: [
require.resolve('@vue/babel-preset-jsx'),
],
})
}
},
ready () {
if (defaultPages.home !== false) {
ctx.addPage({
permalink: '/',
frontmatter: {
title: lang.home,
layout: 'Home',
},
})
}
if (defaultPages.posts !== false) {
ctx.addPage({
permalink: '/posts/',
frontmatter: {
title: lang.posts,
layout: 'Posts',
},
})
}
},
}
return options
}