🎨 Automatic refresh of document tree information https://github.com/siyuan-note/siyuan/issues/11043

This commit is contained in:
Daniel 2024-09-28 23:41:09 +08:00
parent 18c41e000d
commit 63ae805106
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 34 additions and 5 deletions

View file

@ -1741,6 +1741,7 @@ func removeDoc(box *Box, p string, luteEngine *lute.Lute) {
}
util.PushEvent(evt)
refreshParentDocInfo(tree)
task.AppendTask(task.DatabaseIndex, removeDoc0, box, p, childrenDir)
}

View file

@ -17,7 +17,11 @@
package model
import (
"github.com/88250/lute"
"github.com/88250/lute/render"
"github.com/siyuan-note/siyuan/kernel/filesys"
"os"
"path"
"path/filepath"
"strings"
"time"
@ -35,6 +39,31 @@ import (
)
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)
mTime := cTime
if updated := tree.Root.IALAttr("updated"); "" != updated {
@ -59,18 +88,17 @@ func refreshDocInfo(tree *parse.Tree, size uint64) {
docInfo := map[string]interface{}{
"rootID": tree.ID,
"name": tree.Root.IALAttr("title"),
"size": size,
"hSize": humanize.BytesCustomCeil(size, 2),
"mtime": mTime.Unix(),
"ctime": cTime.Unix(),
"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),
"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),
"subFileCount": subFileCount,
}
task.AppendAsyncTaskWithDelay(task.ReloadProtyle, 500*time.Millisecond, util.PushReloadDocInfo, docInfo)
// TODO 子文档修改后也需要递归刷新父文档
}
func refreshProtyle(rootID string) {

View file

@ -91,7 +91,7 @@ func containTask(task *Task, tasks []*Task) bool {
}
for i, arg := range t.Args {
if arg != task.Args[i] {
if !reflect.DeepEqual(arg, task.Args[i]) {
return false
}
}