mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-04 05:42:12 +08:00
🎨 Improve import markdown assets path decoding https://github.com/siyuan-note/siyuan/issues/14033
This commit is contained in:
parent
e40fe2f8b8
commit
1f6d327f24
@ -866,8 +866,16 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
dest = strings.ReplaceAll(dest, "%20", " ")
|
absolutePath := filepath.Join(localPath, dest)
|
||||||
dest = strings.ReplaceAll(dest, "%5C", "/")
|
newAbsolutePath := absolutePath
|
||||||
|
|
||||||
|
decodedDest := string(html.DecodeDestination([]byte(dest)))
|
||||||
|
if decodedDest != dest {
|
||||||
|
dest = decodedDest
|
||||||
|
newAbsolutePath = filepath.Join(localPath, dest)
|
||||||
|
gulu.File.Copy(absolutePath, newAbsolutePath)
|
||||||
|
}
|
||||||
|
|
||||||
if ast.NodeLinkDest == n.Type {
|
if ast.NodeLinkDest == n.Type {
|
||||||
n.Tokens = []byte(dest)
|
n.Tokens = []byte(dest)
|
||||||
} else {
|
} else {
|
||||||
@ -881,6 +889,10 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !gulu.File.IsExist(newAbsolutePath) {
|
||||||
|
return ast.WalkContinue
|
||||||
|
}
|
||||||
|
|
||||||
absDest := filepath.Join(currentDir, dest)
|
absDest := filepath.Join(currentDir, dest)
|
||||||
fullPath, exist := assets[absDest]
|
fullPath, exist := assets[absDest]
|
||||||
if !exist {
|
if !exist {
|
||||||
@ -988,8 +1000,16 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
dest = strings.ReplaceAll(dest, "%20", " ")
|
absolutePath := filepath.Join(filepath.Dir(localPath), dest)
|
||||||
dest = strings.ReplaceAll(dest, "%5C", "/")
|
newAbsolutePath := absolutePath
|
||||||
|
|
||||||
|
decodedDest := string(html.DecodeDestination([]byte(dest)))
|
||||||
|
if decodedDest != dest {
|
||||||
|
dest = decodedDest
|
||||||
|
newAbsolutePath = filepath.Join(filepath.Dir(localPath), dest)
|
||||||
|
gulu.File.Copy(absolutePath, newAbsolutePath)
|
||||||
|
}
|
||||||
|
|
||||||
if ast.NodeLinkDest == n.Type {
|
if ast.NodeLinkDest == n.Type {
|
||||||
n.Tokens = []byte(dest)
|
n.Tokens = []byte(dest)
|
||||||
} else {
|
} else {
|
||||||
@ -1003,25 +1023,21 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
absolutePath := filepath.Join(filepath.Dir(localPath), dest)
|
if !gulu.File.IsExist(newAbsolutePath) {
|
||||||
exist := gulu.File.IsExist(absolutePath)
|
return ast.WalkContinue
|
||||||
if !exist {
|
|
||||||
absolutePath = filepath.Join(filepath.Dir(localPath), string(html.DecodeDestination([]byte(dest))))
|
|
||||||
exist = gulu.File.IsExist(absolutePath)
|
|
||||||
}
|
}
|
||||||
if exist {
|
|
||||||
name := filepath.Base(absolutePath)
|
name := filepath.Base(newAbsolutePath)
|
||||||
name = util.AssetName(name)
|
name = util.AssetName(name)
|
||||||
assetTargetPath := filepath.Join(assetDirPath, name)
|
assetTargetPath := filepath.Join(assetDirPath, name)
|
||||||
if err = filelock.Copy(absolutePath, assetTargetPath); err != nil {
|
if err = filelock.Copy(newAbsolutePath, assetTargetPath); err != nil {
|
||||||
logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", absolutePath, assetTargetPath, err)
|
logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", newAbsolutePath, assetTargetPath, err)
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
if ast.NodeLinkDest == n.Type {
|
if ast.NodeLinkDest == n.Type {
|
||||||
n.Tokens = []byte("assets/" + name)
|
n.Tokens = []byte("assets/" + name)
|
||||||
} else {
|
} else {
|
||||||
n.TextMarkAHref = "assets/" + name
|
n.TextMarkAHref = "assets/" + name
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user