fix(theme): incorrect auto sidebar sorting (#399)

This commit is contained in:
pengzhanbo 2024-12-25 00:16:33 +08:00 committed by GitHub
parent ef113f7df7
commit 0b7a955343
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -95,7 +95,7 @@ function fileSorting(filepath?: string): number | false {
const matched = filepath.match(RE_FILE_SORTING)
const sorted = matched ? Number(matched[1]) : 0
if (Number.isNaN(sorted))
return 0
return Number.MAX_SAFE_INTEGER
return sorted
}
@ -109,11 +109,9 @@ function getAutoDirSidebar(
.map((page) => {
return { ...page, splitPath: page.data.filePathRelative?.split('/') || [] }
})
const maxIndex = Math.max(...pages.map(page => page.splitPath.length))
let nowIndex = 0
while (nowIndex < maxIndex) {
let nowIndex = maxIndex - 1
while (nowIndex >= 0) {
pages = pages.sort((prev, next) => {
const pi = fileSorting(prev.splitPath?.[nowIndex])
const ni = fileSorting(next.splitPath?.[nowIndex])
@ -124,7 +122,7 @@ function getAutoDirSidebar(
return pi < ni ? -1 : 1
})
nowIndex++
nowIndex--
}
const RE_INDEX = ['index.md', 'README.md', 'readme.md']