🐛 复制资源文件后导出再导入后丢失 Fix https://github.com/siyuan-note/siyuan/issues/5320

This commit is contained in:
Liang Ding 2022-06-30 11:29:05 +08:00
parent ea4f722edb
commit a0a3d2f28e
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
3 changed files with 34 additions and 25 deletions

View file

@ -24,6 +24,7 @@ import (
"strings"
"github.com/88250/gulu"
"github.com/88250/lute/ast"
)
func IsEmptyDir(p string) bool {
@ -47,6 +48,23 @@ func RemoveID(name string) string {
return name + ext
}
func AssetName(name string) string {
_, id := LastID(name)
ext := path.Ext(name)
name = name[0 : len(name)-len(ext)]
if !IsIDPattern(id) {
id = ast.NewNodeID()
name = name + "-" + id + ext
} else {
if !IsIDPattern(name) {
name = name[:len(name)-len(id)-1] + "-" + id + ext
} else {
name = name + ext
}
}
return name
}
func LastID(p string) (name, id string) {
name = path.Base(p)
ext := path.Ext(name)