fix: hide docs in leaf directories from tree display
This commit is contained in:
@@ -71,13 +71,25 @@ export const ApiDocViewer = ({ onDocsPathChange, showAddModal, onCloseAddModal }
|
||||
|
||||
setExternalDocs(docs)
|
||||
|
||||
const dirs = new Set(docs.map(d => {
|
||||
const parts = d.relativePath.split('/')
|
||||
return parts.length >= 2 ? parts.slice(0, -1).join('/') : ''
|
||||
}))
|
||||
|
||||
const dirsWithSubdirs = new Set(
|
||||
docs
|
||||
.filter(d => d.relativePath.split('/').length >= 3)
|
||||
.map(d => d.relativePath.split('/').slice(0, -1).join('/'))
|
||||
)
|
||||
|
||||
const leafDirs = new Set([...dirs].filter(d => !dirsWithSubdirs.has(d)))
|
||||
|
||||
const fileList = docs
|
||||
.filter(doc => {
|
||||
const parts = doc.relativePath.split('/')
|
||||
if (parts.length < 2) return true
|
||||
const filename = parts[parts.length - 1].replace(/\.md$/, '')
|
||||
const parentFolder = parts[parts.length - 2]
|
||||
return filename !== parentFolder
|
||||
const parentDir = parts.slice(0, -1).join('/')
|
||||
return !leafDirs.has(parentDir)
|
||||
})
|
||||
.map(d => d.relativePath)
|
||||
const tree = buildFileTree(fileList, '/')
|
||||
|
||||
Reference in New Issue
Block a user