Generate /api/ sidebar

This commit is contained in:
thepaperpilot 2022-03-08 01:03:11 -06:00
parent 1acbe66ba3
commit 8b039b3cd7
2 changed files with 47 additions and 0 deletions

View file

@ -1,3 +1,5 @@
const fs = require("fs");
module.exports = {
lang: "en-US",
title: 'Profectus',
@ -62,6 +64,43 @@ module.exports = {
]
}
],
"/api/": generateAPISidebar()
}
}
}
function generateAPISidebar() {
const modules = fs.readdirSync("./api/modules").map(file => file.substr(0, file.length - 3));
const folders = {};
modules.forEach(file => {
// Split by _, but not break_eternity
const pieces = file.replace("break_eternity", "break~eternity").split(/_/).map(piece => piece === "break~eternity" ? "break_eternity" : piece);
const lineItem = { text: camelToTitle(pieces[pieces.length - 1]), link: `/api/modules/${file}` };
pieces.slice(0, pieces.length - 1).reduce((acc, curr) => {
// console.log(acc, curr);
if (!acc[curr]) {
acc[curr] = { text: camelToTitle(curr), children: [] };
}
return acc[curr].children;
}, folders).push(lineItem);
});
return processFolders(folders);
}
function camelToTitle(camel) {
if (camel === "break_eternity") {
return "Break Eternity";
}
let title = camel.replace(/([A-Z])/g, " $1");
title = title.charAt(0).toUpperCase() + title.slice(1);
return title;
}
function processFolders(folders) {
return Object.values(folders).map(folder => {
if (folder.children) {
folder.children = processFolders(folder.children);
}
return folder;
})
}

View file

@ -14,3 +14,11 @@
tr:nth-child(2n) {
background-color: var(--code-bg-color);
}
.sidebar > .sidebar-links > .sidebar-link > .sidebar-links > .sidebar-link > .sidebar-links > .sidebar-link > .sidebar-links > .sidebar-link > .sidebar-links > .sidebar-link > .sidebar-link-item {
display: block;
padding: 0.3rem 1.5rem 0.3rem 5rem;
line-height: 1.4;
font-size: 0.9rem;
font-weight: 400;
}