-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
index.js
156 lines (145 loc) · 3.18 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
156
const removeMd = require('remove-markdown')
const path = require('path')
const pick = require('lodash/pick')
module.exports = themeConfig => {
/**
* Default theme configuration
*/
themeConfig = Object.assign(themeConfig, {
logo: '/assets/img/logo.png',
nav: themeConfig.nav || [
{
text: 'Blog',
link: '/',
},
{
text: 'Tags',
link: '/tag/',
},
],
summary: themeConfig.summary === undefined ? true : themeConfig.summary,
summaryLength:
typeof themeConfig.summaryLength === 'number'
? themeConfig.summaryLength
: 200,
pwa: !!themeConfig.pwa,
})
/**
* Configure blog plugin
*/
const defaultBlogPluginOptions = {
directories: [
{
id: 'post',
dirname: '_posts',
path: '/',
},
],
frontmatters: [
{
id: 'tag',
keys: ['tags'],
path: '/tag/',
},
],
globalPagination: {
lengthPerPage: 6,
},
}
let resolvedFeedOptions
const isFeedEnabled = themeConfig.feed && themeConfig.feed.canonical_base
if (isFeedEnabled) {
const {
rss = true,
atom = true,
json = true,
...feedOptions
} = themeConfig.feed
resolvedFeedOptions = Object.assign({}, feedOptions, {
feeds: {
rss2: { enable: rss },
atom1: { enable: atom },
json1: { enable: json },
},
})
}
const properties = [
'directories',
'frontmatters',
'globalPagination',
'sitemap',
'comment',
'newsletter',
]
const themeConfigPluginOptions = {
...pick(themeConfig, properties),
feed: resolvedFeedOptions,
}
const blogPluginOptions = Object.assign(
{},
defaultBlogPluginOptions,
themeConfigPluginOptions
)
/**
* Integrate plugins
*/
const enableSmoothScroll = themeConfig.smoothScroll === true
const plugins = [
'@vuepress/plugin-nprogress',
['@vuepress/medium-zoom', true],
[
'@vuepress/search',
{
searchMaxSuggestions: 10,
},
],
['@vuepress/blog', blogPluginOptions],
['smooth-scroll', enableSmoothScroll],
]
/**
* Enable pwa
*/
if (themeConfig.pwa) {
plugins.push([
'@vuepress/pwa',
{
serviceWorker: true,
updatePopup: true,
},
])
}
const config = {
plugins,
define: {
THEME_BLOG_PAGINATION_COMPONENT: themeConfig.paginationComponent
? themeConfig.paginationComponent
: 'Pagination',
},
alias: {
fonts: path.resolve(__dirname, 'fonts'),
},
/**
* Generate summary.
*/
extendPageData(pageCtx) {
const strippedContent = pageCtx._strippedContent
if (!strippedContent) {
return
}
if (themeConfig.summary) {
pageCtx.summary =
removeMd(
strippedContent
.trim()
.replace(/^#+\s+(.*)/, '')
.slice(0, themeConfig.summaryLength)
) + ' ...'
pageCtx.frontmatter.description = pageCtx.summary
}
if (pageCtx.frontmatter.summary) {
pageCtx.frontmatter.description = pageCtx.frontmatter.summary
}
},
}
return config
}