-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
59 lines (53 loc) · 1.53 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
const path = require('path')
function checkRegularPath(regularPath, readingDir, fixed) {
if (readingDir === null) {
return fixed
} else if (typeof readingDir === 'string') {
return setConfig(regularPath, readingDir, fixed)
} else if (Array.isArray(readingDir)) {
for (let i = 0; i < readingDir.length; i++) {
const item = readingDir[i]
const isShow = setConfig(regularPath, item, fixed)
if (isShow) return fixed
}
return false
} else if (readingDir.constructor === RegExp) {
return readingDir.test(regularPath) ? fixed : false
} else {
for (const key in readingDir) {
const item = readingDir[key]
const isShow = setConfig(regularPath, key, item)
if (isShow) return item
}
return false
}
}
function setConfig(regularPath, dir, fixed) {
return regularPath.includes(dir) ? fixed : false
}
module.exports = options => {
const {
readingDir = null,
fixed = 'top'
} = options
return {
extendPageData($page) {
const { regularPath, frontmatter: { readingShow }} = $page
let type = fixed
if (readingShow !== undefined) {
type = typeof readingShow === 'boolean' && readingShow
? fixed
: readingShow
} else if (regularPath) {
type = checkRegularPath(regularPath, readingDir, fixed)
} else {
type = false
}
$page.frontmatter.readingShow = type
},
enhanceAppFiles: [
path.resolve(__dirname, 'enhanceAppFile.js')
],
globalUIComponents: 'ReadingProgress'
}
}