fix: turn the generateSidebar to sync way
This commit is contained in:
@@ -51,11 +51,11 @@ export default withMermaid({
|
|||||||
|
|
||||||
sidebar: {
|
sidebar: {
|
||||||
'/': main_sidebar(),
|
'/': main_sidebar(),
|
||||||
'/1.杭电生存指南/': await generateSidebar('1.杭电生存指南'),
|
'/1.杭电生存指南/': generateSidebar('1.杭电生存指南'),
|
||||||
'/2.编程模块/': await generateSidebar('2.编程模块'),
|
'/2.编程模块/': generateSidebar('2.编程模块'),
|
||||||
'/3.AI模块/': await generateSidebar('3.AI模块'),
|
'/3.AI模块/': generateSidebar('3.AI模块'),
|
||||||
'/4.WEB模块/': await generateSidebar('4.WEB模块'),
|
'/4.WEB模块/': generateSidebar('4.WEB模块'),
|
||||||
'/5.安全模块/': await generateSidebar('5.安全模块'),
|
'/5.安全模块/': generateSidebar('5.安全模块'),
|
||||||
'/2023旧版内容/': main_sidebar_old(),
|
'/2023旧版内容/': main_sidebar_old(),
|
||||||
'/2023旧版内容/2.高效学习/': chapter2_old(),
|
'/2023旧版内容/2.高效学习/': chapter2_old(),
|
||||||
'/2023旧版内容/3.编程思维体系构建/': chapter3_old(),
|
'/2023旧版内容/3.编程思维体系构建/': chapter3_old(),
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import fs from 'fs/promises';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
export function main_sidebar() {
|
export function main_sidebar() {
|
||||||
@@ -547,23 +547,23 @@ function compareNumericPrefixes(a, b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function generateSidebarBasic(dir, excludeDir = [], maxDepth, currentDepth = 0) {
|
export function generateSidebarBasic(dir, excludeDir = [], maxDepth, currentDepth = 0) {
|
||||||
if (currentDepth >= maxDepth)
|
if (currentDepth >= maxDepth)
|
||||||
console.warn("the file depth is beyond the maxium depth that your sidebar can show!");
|
console.warn("the file depth is beyond the maxium depth that your sidebar can show!");
|
||||||
const files = await fs.readdir(dir);
|
const files = fs.readdirSync(dir);
|
||||||
const sortedFiles = files.sort(compareNumericPrefixes);
|
const sortedFiles = files.sort(compareNumericPrefixes);
|
||||||
|
|
||||||
const sidebar = await Promise.all(
|
const sidebar =
|
||||||
sortedFiles.map(async (file) => {
|
sortedFiles.map((file) => {
|
||||||
const fullPath = path.join(dir, file);
|
const fullPath = path.join(dir, file);
|
||||||
const stats = await fs.stat(fullPath);
|
const stats = fs.statSync(fullPath);
|
||||||
|
|
||||||
if (stats.isDirectory()) {
|
if (stats.isDirectory()) {
|
||||||
if (excludeDir.includes(file)) return null; // Skip excluded directories
|
if (excludeDir.includes(file)) return null; // Skip excluded directories
|
||||||
return {
|
return {
|
||||||
text: file,
|
text: file,
|
||||||
collapsed: true,
|
collapsed: true,
|
||||||
items: await generateSidebarBasic(fullPath, excludeDir, maxDepth, ++currentDepth),
|
items: generateSidebarBasic(fullPath, excludeDir, maxDepth, currentDepth + 1),
|
||||||
};
|
};
|
||||||
} else if (file.endsWith('.md')) {
|
} else if (file.endsWith('.md')) {
|
||||||
return {
|
return {
|
||||||
@@ -572,12 +572,11 @@ export async function generateSidebarBasic(dir, excludeDir = [], maxDepth, curre
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
|
||||||
|
|
||||||
return sidebar.filter(Boolean);
|
return sidebar.filter(Boolean);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function generateSidebar(
|
export function generateSidebar(
|
||||||
dir,
|
dir,
|
||||||
{
|
{
|
||||||
excludeDir = ['static'],
|
excludeDir = ['static'],
|
||||||
@@ -595,7 +594,7 @@ export async function generateSidebar(
|
|||||||
{
|
{
|
||||||
text: topLevelName ?? dir,
|
text: topLevelName ?? dir,
|
||||||
collapsed: false,
|
collapsed: false,
|
||||||
items: await generateSidebarBasic(dir, excludeDir, maxDepth),
|
items: generateSidebarBasic(dir, excludeDir, maxDepth),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
return sidebar;
|
return sidebar;
|
||||||
|
|||||||
Reference in New Issue
Block a user