From a15899d4211a6a2c75d1af7ed180efd7a19af4b0 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 28 Oct 2024 10:20:33 +0800 Subject: [PATCH] :art: Display document title in data history preview area https://github.com/siyuan-note/siyuan/issues/12948 --- kernel/api/repo.go | 3 ++- kernel/model/repository.go | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/kernel/api/repo.go b/kernel/api/repo.go index 14cb0e34f..f0b917e85 100644 --- a/kernel/api/repo.go +++ b/kernel/api/repo.go @@ -70,7 +70,7 @@ func openRepoSnapshotDoc(c *gin.Context) { } id := arg["id"].(string) - content, isProtyleDoc, updated, err := model.OpenRepoSnapshotDoc(id) + title, content, isProtyleDoc, updated, err := model.OpenRepoSnapshotDoc(id) if err != nil { ret.Code = -1 ret.Msg = err.Error() @@ -78,6 +78,7 @@ func openRepoSnapshotDoc(c *gin.Context) { } ret.Data = map[string]interface{}{ + "title": title, "content": content, "isProtyleDoc": isProtyleDoc, "updated": updated, diff --git a/kernel/model/repository.go b/kernel/model/repository.go index a11249a77..86e916e17 100644 --- a/kernel/model/repository.go +++ b/kernel/model/repository.go @@ -79,7 +79,7 @@ func GetRepoFile(fileID string) (ret []byte, p string, err error) { return } -func OpenRepoSnapshotDoc(fileID string) (content string, isProtyleDoc bool, updated int64, err error) { +func OpenRepoSnapshotDoc(fileID string) (title, content string, isProtyleDoc bool, updated int64, err error) { if 1 > len(Conf.Repo.Key) { err = errors.New(Conf.Language(26)) return @@ -110,6 +110,7 @@ func OpenRepoSnapshotDoc(fileID string) (content string, isProtyleDoc bool, upda logging.LogErrorf("parse tree from snapshot file [%s] failed", fileID) return } + title = snapshotTree.Root.IALAttr("title") if !isProtyleDoc { renderTree := &parse.Tree{Root: &ast.Node{Type: ast.NodeDocument}} @@ -150,6 +151,7 @@ func OpenRepoSnapshotDoc(fileID string) (content string, isProtyleDoc bool, upda } } else { isProtyleDoc = true + title = path.Base(file.Path) if strings.HasSuffix(file.Path, ".json") { content = gulu.Str.FromBytes(data) } else {