diff --git a/src/components/ApiDocViewer.tsx b/src/components/ApiDocViewer.tsx index 5f30ad5..ec48f0e 100644 --- a/src/components/ApiDocViewer.tsx +++ b/src/components/ApiDocViewer.tsx @@ -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, '/')