diff --git a/lib/index.ts b/lib/index.ts index 14545b32..1f2a9b1e 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -326,15 +326,17 @@ export default class VitePressSidebar { ) || []; let newDirectoryText = VitePressSidebar.getTitleFromMd(x, childItemPath, options, true); + let newDirectoryPagePath = childItemPath; let withDirectoryLink; if (options.convertSameNameSubFileToGroupIndexPage) { const findItem = directorySidebarItems.find((y: SidebarListItem) => y.text === x); if (findItem) { + newDirectoryPagePath = resolve(childItemPath, `${findItem.text}.md`); newDirectoryText = VitePressSidebar.getTitleFromMd( x, - resolve(childItemPath, `${findItem.text}.md`), + newDirectoryPagePath, options, false ); @@ -353,13 +355,13 @@ export default class VitePressSidebar { // If an index.md file exists in a folder subfile, // replace the name or link of the folder with what is set in index.md. // The index.md file can still be displayed if the value of `includeFolderIndexFile` is `true`. - const childIndexFilePath = `${childItemPath}/index.md`; + newDirectoryPagePath = `${childItemPath}/index.md`; - if (existsSync(childIndexFilePath)) { + if (existsSync(newDirectoryPagePath)) { if (options.useFolderTitleFromIndexFile) { newDirectoryText = VitePressSidebar.getTitleFromMd( 'index', - childIndexFilePath, + newDirectoryPagePath, options ); } @@ -376,7 +378,10 @@ export default class VitePressSidebar { items: directorySidebarItems, ...(options.collapsed === null || options.collapsed === undefined ? {} - : { collapsed: depth >= options.collapseDepth! && options.collapsed }) + : { collapsed: depth >= options.collapseDepth! && options.collapsed }), + ...(options.sortMenusByFrontmatterOrder + ? { order: VitePressSidebar.getOrderFromFrontmatter(newDirectoryPagePath) } + : {}) }; }