forked from thecodingmachine/symfony-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sidebars.js
49 lines (45 loc) · 1.25 KB
/
sidebars.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
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
const fs = require('fs')
const autoGenerated = (root = 'docs', path = root) => fs.readdirSync(path).filter(x => x !== 'assets').reduce((acc, item) => {
if (fs.lstatSync(`${path}/${item}`).isDirectory()) {
const listOfFilesInDirectory = autoGenerated(root, `${path}/${item}`)
return {
...acc,
...listOfFilesInDirectory || {}
}
}
const actualPath = path.split(`${root}/`)[1] || 'others'
const olderValues = actualPath !== 'others' ? (acc[path.split(`${root}/`)[1]] || []) : (acc.others || [])
return {
...acc,
[actualPath]: [
...olderValues,
`${path.split(`${root}/`).slice(1)}/${item}`.replace(/\.[^.]*$/, ''),
]
}
}, {})
module.exports = {
docs: Object.entries(autoGenerated()).reduce((acc, [key, value]) => {
if (key !== 'others') {
return [
...acc,
{
type: 'category',
label: key.replace(/^[^_]*_/, ''),
items: value,
},
]
}
return [
...acc,
...value.map(item=> ({type: 'doc', id: item.split('/').pop()}))
]
}, [])
};