mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 Automatic refresh of document tree information https://github.com/siyuan-note/siyuan/issues/11043
This commit is contained in:
parent
18c41e000d
commit
63ae805106
3 changed files with 34 additions and 5 deletions
|
|
@ -1741,6 +1741,7 @@ func removeDoc(box *Box, p string, luteEngine *lute.Lute) {
|
||||||
}
|
}
|
||||||
util.PushEvent(evt)
|
util.PushEvent(evt)
|
||||||
|
|
||||||
|
refreshParentDocInfo(tree)
|
||||||
task.AppendTask(task.DatabaseIndex, removeDoc0, box, p, childrenDir)
|
task.AppendTask(task.DatabaseIndex, removeDoc0, box, p, childrenDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,11 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/88250/lute"
|
||||||
|
"github.com/88250/lute/render"
|
||||||
|
"github.com/siyuan-note/siyuan/kernel/filesys"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -35,6 +39,31 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func refreshDocInfo(tree *parse.Tree, size uint64) {
|
func refreshDocInfo(tree *parse.Tree, size uint64) {
|
||||||
|
refreshDocInfo0(tree, size)
|
||||||
|
refreshParentDocInfo(tree)
|
||||||
|
}
|
||||||
|
|
||||||
|
func refreshParentDocInfo(tree *parse.Tree) {
|
||||||
|
luteEngine := lute.New()
|
||||||
|
boxDir := filepath.Join(util.DataDir, tree.Box)
|
||||||
|
parentDir := path.Dir(tree.Path)
|
||||||
|
parentPath := parentDir + ".sy"
|
||||||
|
|
||||||
|
if parentDir == boxDir || parentDir == "/" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
parentTree, err := filesys.LoadTree(tree.Box, parentPath, luteEngine)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer := render.NewJSONRenderer(parentTree, luteEngine.RenderOptions)
|
||||||
|
data := renderer.Render()
|
||||||
|
refreshDocInfo0(parentTree, uint64(len(data)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func refreshDocInfo0(tree *parse.Tree, size uint64) {
|
||||||
cTime, _ := time.ParseInLocation("20060102150405", tree.ID[:14], time.Local)
|
cTime, _ := time.ParseInLocation("20060102150405", tree.ID[:14], time.Local)
|
||||||
mTime := cTime
|
mTime := cTime
|
||||||
if updated := tree.Root.IALAttr("updated"); "" != updated {
|
if updated := tree.Root.IALAttr("updated"); "" != updated {
|
||||||
|
|
@ -59,18 +88,17 @@ func refreshDocInfo(tree *parse.Tree, size uint64) {
|
||||||
|
|
||||||
docInfo := map[string]interface{}{
|
docInfo := map[string]interface{}{
|
||||||
"rootID": tree.ID,
|
"rootID": tree.ID,
|
||||||
|
"name": tree.Root.IALAttr("title"),
|
||||||
"size": size,
|
"size": size,
|
||||||
"hSize": humanize.BytesCustomCeil(size, 2),
|
"hSize": humanize.BytesCustomCeil(size, 2),
|
||||||
"mtime": mTime.Unix(),
|
"mtime": mTime.Unix(),
|
||||||
"ctime": cTime.Unix(),
|
"ctime": cTime.Unix(),
|
||||||
"hmtime": cTime.Format("2006-01-02 15:04:05") + ", " + util.HumanizeTime(mTime, Conf.Lang),
|
"hMtime": cTime.Format("2006-01-02 15:04:05") + ", " + util.HumanizeTime(mTime, Conf.Lang),
|
||||||
"hctime": mTime.Format("2006-01-02 15:04:05") + ", " + util.HumanizeTime(cTime, Conf.Lang),
|
"hCtime": mTime.Format("2006-01-02 15:04:05") + ", " + util.HumanizeTime(cTime, Conf.Lang),
|
||||||
"subFileCount": subFileCount,
|
"subFileCount": subFileCount,
|
||||||
}
|
}
|
||||||
|
|
||||||
task.AppendAsyncTaskWithDelay(task.ReloadProtyle, 500*time.Millisecond, util.PushReloadDocInfo, docInfo)
|
task.AppendAsyncTaskWithDelay(task.ReloadProtyle, 500*time.Millisecond, util.PushReloadDocInfo, docInfo)
|
||||||
|
|
||||||
// TODO 子文档修改后也需要递归刷新父文档
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func refreshProtyle(rootID string) {
|
func refreshProtyle(rootID string) {
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ func containTask(task *Task, tasks []*Task) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, arg := range t.Args {
|
for i, arg := range t.Args {
|
||||||
if arg != task.Args[i] {
|
if !reflect.DeepEqual(arg, task.Args[i]) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue