-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathbuild-sidebar.js
More file actions
49 lines (35 loc) · 1.64 KB
/
build-sidebar.js
File metadata and controls
49 lines (35 loc) · 1.64 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
const fs = require("fs");
const documentationFolder = "docs";
async function getFiles (directory) {
const files = [];
const dir = fs.opendirSync(directory);
for await (const dirent of dir) {
files.push(dirent.name);
}
return files.sort();
}
function filenameToTitle (filename) {
return filename.split(".").shift().replace(/_/g, " ");
}
async function buildSection (directory) {
const files = await getFiles(`${documentationFolder}/${directory}`);
const title = filenameToTitle(directory);
const content = [`- ${title}\n`];
for (const file of files) {
content.push(`\t- [${filenameToTitle(file)}](${directory}/${file})`);
}
return content.join("\n");
}
async function buildSidebar (watchEventType) {
if (watchEventType == "change") { return; }
console.log("Building _sidebar.md");
const content = `- [Home](README.md) \n\n` + await buildSection("JavaScript_Basics_Info") + "\n\n\n" + await buildSection("JavaScript_Advance_Info")+ "\n\n\n" + await buildSection("JavaScript_Basics") + "\n\n\n" + await buildSection("JavaScript_Advance") + "\n\n" + await buildSection("Exercise_Questions") + "\n\n" + await buildSection("Reference");
fs.writeFileSync(`${documentationFolder}/_sidebar.md`, content);
}
fs.watch(`${documentationFolder}/JavaScript_Basics_Info`, buildSidebar);
fs.watch(`${documentationFolder}/JavaScript_Advance_Info`, buildSidebar);
fs.watch(`${documentationFolder}/JavaScript_Basics`, buildSidebar);
fs.watch(`${documentationFolder}/JavaScript_Advance`, buildSidebar);
fs.watch(`${documentationFolder}/Exercise_Questions`, buildSidebar);
fs.watch(`${documentationFolder}/Reference`, buildSidebar);
buildSidebar();