-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
115 lines (113 loc) · 3.8 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
module.exports = (themeConfig) => {
// default config
const defaultConfig = {
logo: ['text', '2zh'],
notice: [],
pagination: 12,
author: '2zh',
links: [],
domain: '',
comment: []
}
for (let key in defaultConfig) {
themeConfig[key] = themeConfig[key] || defaultConfig[key]
}
// pagination sort function
function sorter(prev, next) {
const prevPined = prev.frontmatter.pined
const nextPined = next.frontmatter.pined
if (!prevPined && !nextPined) {
const day = require('dayjs')
const prevDate = day(prev.frontmatter.date)
const nextDate = day(next.frontmatter.date)
return nextDate - prevDate
} else if (!prevPined && nextPined) {
return 1
} else if (prevPined && !nextPined) {
return -1
} else {
return prevPined - nextPined
}
}
const pluginConfig = {
plugins: [
[
'@vuepress/plugin-blog',
{
directories: [
{
id: 'post',
dirname: 'post',
path: '/',
frontmatter: {
title: 'Index',
layout: 'Index'
},
itemLayout: 'Post',
itemPermalink: '/post/:slug',
pagination: {
lengthPerPage: themeConfig.pagination,
layout: 'Index',
getPaginationPageTitle: (num) => {
return `${num} - Index`
},
sorter
}
}
],
frontmatters: [
{
id: 'tag',
keys: ['tag'],
path: '/search/',
frontmatter: {
title: 'Search',
layout: 'Search'
},
title: '- Search',
scopeLayout: 'Tag',
pagination: {
lengthPerPage: Infinity,
sorter
}
}
],
feed: themeConfig.domain && {
canonical_base: themeConfig.domain,
}
}
],
[
'@vuepress/plugin-search',
{
searchMaxSuggestions: 10
}
],
[
'@vuepress/plugin-medium-zoom',
{
selector: '.component-content img',
delay: 1000,
options: {
background: 'rgba(0, 0, 0, .5)'
}
}
],
[
// webpack externals 引入 cdn
(pluginOptions, context) => ({
name: '2zh-webpack-externals-plugin',
chainWebpack (config) {
config['externals']({
cdn_nprogress: 'NProgress',
cdn_mermaid: 'mermaid',
cdn_renderMath: 'renderMathInElement',
cdn_valine: 'Valine'
})
}
})
]
]
}
return pluginConfig
}