fix: strip api/ prefix from externalDocs, remove harmful filtering, fix nested folder click
This commit is contained in:
@@ -65,22 +65,13 @@ export const ApiDocViewer = ({ onDocsPathChange, showAddModal, onCloseAddModal }
|
||||
for (const file of files) {
|
||||
const content = await window.electronAPI.readDocFile(file.path)
|
||||
if (content) {
|
||||
docs.push({ name: file.name, path: file.path, relativePath: file.relativePath, content })
|
||||
docs.push({ name: file.name, path: file.path, relativePath: file.relativePath.replace(/^api\//, ''), content })
|
||||
}
|
||||
}
|
||||
|
||||
setExternalDocs(docs)
|
||||
|
||||
// 过滤掉与父文件夹同名的 md 文件,只用于目录树显示
|
||||
const filteredDocs = 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 fileList = filteredDocs.map(d => d.relativePath.replace(/^api\//, ''))
|
||||
const fileList = docs.map(d => d.relativePath)
|
||||
const tree = buildFileTree(fileList, '/')
|
||||
setFileTree(tree)
|
||||
|
||||
@@ -106,12 +97,14 @@ export const ApiDocViewer = ({ onDocsPathChange, showAddModal, onCloseAddModal }
|
||||
}, [externalDocs])
|
||||
|
||||
const handleFolderClick = useCallback((folderPath: string) => {
|
||||
const parts = folderPath.split('/')
|
||||
const basename = parts[parts.length - 1]
|
||||
const sameNameDoc = externalDocs.find(d =>
|
||||
d.relativePath.endsWith(`/${folderPath}.md`)
|
||||
d.relativePath.endsWith(`/${basename}.md`)
|
||||
)
|
||||
|
||||
if (sameNameDoc) {
|
||||
setSelectedPath(sameNameDoc.relativePath.replace(/^api\//, ''))
|
||||
setSelectedPath(sameNameDoc.relativePath)
|
||||
setCurrentContent(sameNameDoc.content)
|
||||
}
|
||||
}, [externalDocs])
|
||||
@@ -133,7 +126,7 @@ export const ApiDocViewer = ({ onDocsPathChange, showAddModal, onCloseAddModal }
|
||||
return docPath === ref || docPath.endsWith('/' + ref.split('/').pop())
|
||||
})
|
||||
if (match) {
|
||||
setSelectedPath(match.relativePath.replace(/^api\//, ''))
|
||||
setSelectedPath(match.relativePath)
|
||||
setCurrentContent(match.content)
|
||||
}
|
||||
}, [externalDocs])
|
||||
|
||||
Reference in New Issue
Block a user