forked from iotaledger/documentation-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildList.js
44 lines (38 loc) · 1.25 KB
/
buildList.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
const { readdirSync, statSync } = require('fs')
const { join } = require('path')
const getProjects = dir => readdirSync(dir).filter(f => statSync(join(dir, f)).isDirectory())
const listFiles = dir => statSync(dir).isDirectory()
? Array.prototype.concat(...readdirSync(dir).map(f => listFiles(join(dir, f))))
: dir;
const getDocPages = baseDir => {
const dirs = getProjects(baseDir)
const files = Array.prototype.concat(...dirs.map(dir =>
listFiles(`${baseDir}/${dir}`).map(file => ({
path: file.replace('.md',''),
title: `${dir} ${file.replace(`docs/${dir}/`, '').replace('.md','')}`,
markdownSrc: file
}))
))
return files
}
const buildMenuItems = baseDir => {
const projects = getProjects(baseDir)
const menu = {}
const versions = {}
projects.forEach(name => {
const projectVersions = getProjects(`${baseDir}/${name}/reference`)
projectVersions.forEach(version => {
const children = listFiles(`${baseDir}/${name}/reference/${version}`).map(file => ({
name: file.match(/[^\/]+$/)[0].replace('.md', ''),
link: `/${file.replace('.md', '')}`
}))
versions[version] = children
})
menu[name] = { name, versions }
})
return menu
}
module.exports = {
getDocPages,
buildMenuItems
}