-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
127 lines (114 loc) · 2.66 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
const removeMd = require("remove-markdown");
module.exports = (themeConfig, ctx) => {
themeConfig = Object.assign(themeConfig, {
summary: !!themeConfig.summary,
summaryLength:
typeof themeConfig.summaryLength === "number"
? themeConfig.summaryLength
: 200,
pwa: !!themeConfig.pwa
});
themeConfig.heroImage =
themeConfig.heroImage || "https://source.unsplash.com/random/800x600";
const defaultBlogPluginOptions = {
directories: [
{
id: "post",
dirname: "_posts",
path: "/",
// layout: 'IndexPost', defaults to `Layout.vue`
itemLayout: "Post",
frontmatter: { title: "Home" },
itemPermalink: "/:year/:month/:day/:slug",
pagination: {
lengthPerPage: 10
}
}
],
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 = [
"disqus",
"seo",
"reading-time",
"smooth-scroll",
"reading-progress",
"@vuepress/medium-zoom",
"@vuepress/nprogress",
["@vuepress/blog", blogPluginOptions],
[
"@vuepress/search",
{
searchMaxSuggestions: 10
}
]
];
if (themeConfig.sitemap && themeConfig.hostname) {
plugins.push([
"sitemap",
{
hostname: themeConfig.hostname
}
]);
}
if (themeConfig.googleAnalytics) {
plugins.push([
"@vuepress/google-analytics",
{
ga: themeConfig.googleAnalytics
}
]);
}
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;
};