import fs from 'fs';
import path from 'path';
const collapsible = false;
function mapDirToSidebar(pathStr) {
const sidebarArr = [];
const fullPath = path.resolve(__dirname, `..${pathStr}`);
const files = fs.readdirSync(fullPath);
files.forEach((fileName) => {
const childFileName = path.join(fullPath, fileName);
const stats = fs.statSync(childFileName);
if (stats.isDirectory()) {
const textName = fileName.split('-')[1];
sidebarArr.push({
text: textName || fileName,
children: mapDirToSidebar(`${pathStr}/${fileName}`),
collapsible,
})
}
if (stats.isFile()) {
sidebarArr.push(`${pathStr}/${fileName}`);
}
});
console.log(`${pathStr}: `, sidebarArr);
return sidebarArr;
}
export default {
'/life/': mapDirToSidebar('/life'),
'/work/': mapDirToSidebar('/work'),
'/': ["/"],
}