forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflat-menu.js
More file actions
60 lines (50 loc) · 1.19 KB
/
flat-menu.js
File metadata and controls
60 lines (50 loc) · 1.19 KB
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
const join = require('path').join
const menu = require('../src/assets/menu')
const flatMenu = {}
const prefix = join(__dirname, '../src/pages')
let prev
function menuWalk (node, path, parentName) {
const newPath = path + (node.path ? `/${node.path}` : '')
if (node.children !== void 0) {
node.children.forEach(n => {
menuWalk(n, newPath, node.name)
})
}
else if (!node.external) {
const current = {
name: node.name,
category: parentName,
path: newPath
}
if (prev !== void 0) {
prev.next = {
name: current.name,
category: current.category,
path: current.path
}
current.prev = {
name: prev.name,
category: prev.category,
path: prev.path
}
}
flatMenu[join(prefix, newPath + '.md')] = current
prev = current
}
}
menu.forEach(n => {
menuWalk(n, '', null)
})
module.exports.flatMenu = flatMenu
module.exports.convertToRelated = function (entry) {
const menu = flatMenu[join(prefix, entry + '.md')]
if (!menu) {
console.error('Erroneous related link: ' + entry)
return {}
}
return {
name: menu.name,
category: menu.category,
path: menu.path
}
}