-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
83 lines (78 loc) · 2.24 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
const slugify = require("@vuepress/shared-utils/lib/slugify.js")
const path = require("path")
function addSectionHeadings(content, $page) {
let match
// make sure the pattern has the global flag
const sectionRE = RegExp(/<PageSection([^>]*)>/, "g"),
attributesRE = RegExp(/([a-z0-9]+)="([^"]*)"/, "ig")
// console.info($page.headers)
while ((match = sectionRE.exec(content))) {
const attibutes = []
let id = null,
title = null
while ((match_attr = attributesRE.exec(match[1]))) {
const key = match_attr[1],
val = match_attr[2]
switch (key) {
case "id":
id = val
break
case "title":
title = val
break
}
}
const slug = id ? id : slugify(title)
if (!$page.headers) {
$page.headers = []
}
$page.headers.push({ level: 2, title, slug })
}
// console.info($page.headers)
}
module.exports = {
extend: "@vuepress/theme-default",
alias: {
fonts: path.resolve(__dirname, "fonts"),
},
plugins: [
[
"vuepress-plugin-container",
{
type: "section",
before: (info) => `<PageSection title="${info}">`,
after: "</PageSection>",
},
],
],
extendPageData($page) {
const {
_filePath, // file's absolute path
_computed, // access the client global computed mixins at build time, e.g _computed.$localePath.
_content, // file's raw content string
_strippedContent, // file's content string without frontmatter
key, // page's unique hash key
frontmatter, // page's frontmatter object
regularPath, // current page's default link (follow the file hierarchy)
path, // current page's real link (use regularPath when permalink does not exist)
} = $page
addSectionHeadings(_strippedContent, $page)
},
chainWebpack: (config) => {
const svgRule = config.module.rule("svg")
svgRule.uses.clear()
svgRule
.use("babel-loader")
.loader("babel-loader")
.end()
.use("vue-svg-loader")
.loader("vue-svg-loader")
.options({
svgo: {
plugins: [{ removeDoctype: true }, { removeComments: true }, { removeViewBox: false }],
removeViewBox: false,
},
})
.end()
},
}