🎨 文档数据文件 ID 重复时自动重置 ID Fix https://github.com/siyuan-note/siyuan/issues/7340

This commit is contained in:
Liang Ding 2023-02-12 00:23:53 +08:00
parent 698f130ffa
commit 1015ef4037
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
2 changed files with 57 additions and 45 deletions

View file

@ -38,14 +38,18 @@ import (
func resetTree(tree *parse.Tree, titleSuffix string) {
tree.ID = ast.NewNodeID()
tree.Root.ID = tree.ID
if t, parseErr := time.Parse("20060102150405", util.TimeFromID(tree.ID)); nil == parseErr {
titleSuffix += " " + t.Format("2006-01-02 15:04:05")
} else {
titleSuffix = "Duplicated " + time.Now().Format("2006-01-02 15:04:05")
if "" != titleSuffix {
if t, parseErr := time.Parse("20060102150405", util.TimeFromID(tree.ID)); nil == parseErr {
titleSuffix += " " + t.Format("2006-01-02 15:04:05")
} else {
titleSuffix = "Duplicated " + time.Now().Format("2006-01-02 15:04:05")
}
titleSuffix = "(" + titleSuffix + ")"
titleSuffix = " " + titleSuffix
}
titleSuffix = "(" + titleSuffix + ")"
tree.Root.SetIALAttr("id", tree.ID)
tree.Root.SetIALAttr("title", tree.Root.IALAttr("title")+" "+titleSuffix)
tree.Root.SetIALAttr("title", tree.Root.IALAttr("title")+titleSuffix)
tree.Root.RemoveIALAttr("scroll")
p := path.Join(path.Dir(tree.Path), tree.ID) + ".sy"
tree.Path = p