feat: support opening markdown smb files on Windows

This commit is contained in:
purocean
2025-01-23 18:18:27 +08:00
parent 554a569133
commit d9fca0b4f1
2 changed files with 7 additions and 3 deletions
+6 -2
View File
@@ -71,7 +71,9 @@ function getExcludeRegex () {
}
function withRepo<T> (repo = 'main', callback: (repoPath: string, ...targetPath: string[]) => Promise<T>, ...target: string[]): Promise<T> {
const repoPath = repo.startsWith(ROOT_REPO_NAME_PREFIX)
const isRootRepo = repo.startsWith(ROOT_REPO_NAME_PREFIX)
const repoPath = isRootRepo
? repo.substring(ROOT_REPO_NAME_PREFIX.length)
: repository.getPath(repo)
@@ -80,7 +82,9 @@ function withRepo<T> (repo = 'main', callback: (repoPath: string, ...targetPath:
}
return callback(repoPath, ...target.map(x => {
const targetPath = path.join(repoPath, x)
const targetPath = isRootRepo
? x.replace(/^\//, repoPath) // replace first / to repoPath for case of `\\127.0.0.1/test/a.md`
: path.join(repoPath, x)
if (!targetPath.startsWith(repoPath)) {
throw new Error('Path error.')
+1 -1
View File
@@ -887,7 +887,7 @@ export async function switchDocByPath (path: string): Promise<void> {
let root = '/'
if (isWindows) {
const regMatch = path.match(/^([a-zA-Z]:\\)/)
const regMatch = path.match(/^([a-zA-Z]:\\|\\\\)/)
if (regMatch) {
root = regMatch[1]
path = path.replace(root, '/')