-
Notifications
You must be signed in to change notification settings - Fork 6
/
sidebars.js
74 lines (63 loc) · 2.13 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const fs = require('fs');
const path = require('path');
const docsDirectory = path.join(__dirname, 'docs');
let projects = fs.readdirSync(docsDirectory);
// Edit this object to set the order of projects.
// - Keys should be the same as the name of the folder
// - Lower numbers go first.
// - Projects not listed will be added alphabetically at the end.
const ordering = {
"ignite-cli": 10,
"reactotron":20,
"nsfw-js":30,
"apisauce": 40,
"react-native-mlkit":50,
"gluegun":60,
"solidarity":70,
};
// Sort projects based on the ordering object
projects = projects.sort((a, b) => {
const orderA = ordering[a];
const orderB = ordering[b];
if (orderA !== undefined && orderB !== undefined) {
return orderA - orderB;
} else if (orderA !== undefined) {
return 1;
} else if (orderB !== undefined) {
return -1;
} else {
return a.localeCompare(b); // Alphabetical order for projects not in the ordering object
}
});
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
const sidebars = {};
// Gather all the repository URLs
const repoUrls = {
"//": "This JSON is automatically generated with '_category_.json' in each document located in the '/docs' directory.",
};
function fileExists(path) {
try {
return fs.lstatSync(path).isFile();
} catch {
return false;
}
}
projects.forEach((project) => {
const docsDir = path.join(docsDirectory, project);
const realPath = fs.lstatSync(docsDir).isSymbolicLink() ? fs.realpathSync(docsDir) : docsDir;
if (fs.statSync(realPath).isDirectory()) {
const categoryFile = path.join(realPath, "_category_.json");
if (fileExists(categoryFile)) {
const category = require(categoryFile);
sidebars[category.label] = [category.customProps.sidebar];
repoUrls[project] = category.customProps.repoUrl;
} else {
sidebars[project] = [{type: 'autogenerated', dirName: project}];
}
}
});
fs.writeFileSync(
path.join(__dirname, "static", "repo-urls.json"),
JSON.stringify(repoUrls, null, 2)
);
module.exports = sidebars;