forked from vuepress/vuepress-theme-blog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
96 lines (87 loc) · 2.13 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
const removeMd = require('remove-markdown')
module.exports = (themeConfig, ctx) => {
themeConfig = Object.assign(
themeConfig,
{
summary: themeConfig.summary === undefined ? true : themeConfig.summary,
summaryLength: typeof themeConfig.summaryLength === 'number' ? themeConfig.summaryLength : 200,
pwa: !!themeConfig.pwa,
}
)
const defaultBlogPluginOptions = {
directories: [
{
id: 'post',
dirname: '_posts',
path: '/',
// layout: 'IndexPost', defaults to `Layout.vue`
itemLayout: 'Post',
itemPermalink: '/:year/:month/:day/:slug',
pagination: {
lengthPerPage: 5,
},
},
],
frontmatters: [
{
id: "tag",
keys: ['tag', 'tags'],
path: '/tag/',
// layout: 'Tag', defaults to `FrontmatterKey.vue`
frontmatter: { title: 'Tag' },
pagination: {
lengthPerPage: 5
}
},
]
}
const { modifyBlogPluginOptions } = themeConfig
const blogPluginOptions = typeof modifyBlogPluginOptions === 'function'
? modifyBlogPluginOptions(defaultBlogPluginOptions)
: defaultBlogPluginOptions
const plugins = [
'@vuepress/plugin-nprogress',
['@vuepress/medium-zoom', true],
['@vuepress/search', {
searchMaxSuggestions: 10
}],
[
'@vuepress/blog',
blogPluginOptions,
],
]
if (themeConfig.pwa) {
plugins.push(
['@vuepress/pwa', {
serviceWorker: true,
updatePopup: true
}],
)
}
const config = {
plugins,
define: {
THEME_BLOG_PAGINATION_COMPONENT: themeConfig.paginationComponent
? themeConfig.paginationComponent
: 'Pagination'
}
}
/**
* Generate summary.
*/
if (themeConfig.summary) {
config.extendPageData = function (pageCtx) {
const strippedContent = pageCtx._strippedContent
if (!strippedContent) {
return
}
pageCtx.summary = removeMd(
strippedContent
.trim()
.replace(/^#+\s+(.*)/, '')
.slice(0, themeConfig.summaryLength)
) + ' ...'
}
}
return config
}