mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
3d50e40177
commit
fc4cadfd58
5 changed files with 44 additions and 36 deletions
|
|
@ -25,41 +25,6 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func getDocOutlineAndStorage(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
if nil == arg["id"] {
|
||||
return
|
||||
}
|
||||
preview := false
|
||||
if previewArg := arg["preview"]; nil != previewArg {
|
||||
preview = previewArg.(bool)
|
||||
}
|
||||
rootID := arg["id"].(string)
|
||||
data, err := model.GetOutlineStorage(rootID)
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
headings, err := model.Outline(rootID, preview)
|
||||
if err != nil {
|
||||
ret.Code = 1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
ret.Data = map[string]any{
|
||||
"headings": headings,
|
||||
"storage": data,
|
||||
}
|
||||
}
|
||||
|
||||
func getDocOutline(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
|
|
|||
|
|
@ -151,7 +151,6 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||
ginServer.Handle("POST", "/api/history/getHistoryItems", model.CheckAuth, model.CheckAdminRole, getHistoryItems)
|
||||
|
||||
ginServer.Handle("POST", "/api/outline/getDocOutline", model.CheckAuth, getDocOutline)
|
||||
ginServer.Handle("POST", "/api/outline/getDocOutlineAndStorage", model.CheckAuth, getDocOutlineAndStorage)
|
||||
|
||||
ginServer.Handle("POST", "/api/bookmark/getBookmark", model.CheckAuth, getBookmark)
|
||||
ginServer.Handle("POST", "/api/bookmark/renameBookmark", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, renameBookmark)
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@ type Path struct {
|
|||
Children []*Path `json:"children,omitempty"` // 子路径节点
|
||||
Depth int `json:"depth"` // 层级深度
|
||||
Count int `json:"count"` // 子块计数
|
||||
Folded bool `json:"folded"` // 是否折叠
|
||||
|
||||
Updated string `json:"updated"` // 更新时间
|
||||
Created string `json:"created"` // 创建时间
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/88250/lute/html"
|
||||
"github.com/88250/lute/parse"
|
||||
|
|
@ -236,9 +237,43 @@ func Outline(rootID string, preview bool) (ret []*Path, err error) {
|
|||
}
|
||||
|
||||
ret = outline(tree)
|
||||
|
||||
storage, _ := GetOutlineStorage(rootID)
|
||||
if nil == storage {
|
||||
// 默认展开顶层
|
||||
for _, p := range ret {
|
||||
p.Folded = false
|
||||
}
|
||||
}
|
||||
|
||||
if nil != storage["expandIds"] {
|
||||
expandIDsArg := storage["expandIds"].([]interface{})
|
||||
var expandIDs []string
|
||||
for _, id := range expandIDsArg {
|
||||
expandIDs = append(expandIDs, id.(string))
|
||||
}
|
||||
|
||||
for _, p := range ret {
|
||||
p.Folded = false // 顶层默认展开
|
||||
|
||||
for _, b := range p.Blocks {
|
||||
b.Folded = !gulu.Str.Contains(b.ID, expandIDs)
|
||||
for _, c := range b.Children {
|
||||
walkChildren(c, expandIDs)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func walkChildren(b *Block, expandIDs []string) {
|
||||
b.Folded = !gulu.Str.Contains(b.ID, expandIDs)
|
||||
for _, c := range b.Children {
|
||||
walkChildren(c, expandIDs)
|
||||
}
|
||||
}
|
||||
|
||||
func outline(tree *parse.Tree) (ret []*Path) {
|
||||
luteEngine := NewLute()
|
||||
var headings []*Block
|
||||
|
|
@ -254,6 +289,7 @@ func outline(tree *parse.Tree) (ret []*Path) {
|
|||
Content: renderOutline(n, luteEngine),
|
||||
Type: n.Type.String(),
|
||||
SubType: treenode.SubTypeAbbr(n),
|
||||
Folded: true,
|
||||
}
|
||||
headings = append(headings, block)
|
||||
return ast.WalkSkipChildren
|
||||
|
|
@ -303,6 +339,7 @@ func outline(tree *parse.Tree) (ret []*Path) {
|
|||
Blocks: b.Children,
|
||||
Depth: 0,
|
||||
Count: b.Count,
|
||||
Folded: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -149,6 +149,11 @@ func toFlatTree(blocks []*Block, baseDepth int, typ string, tree *parse.Tree) (r
|
|||
root.Children = append(root.Children, block)
|
||||
}
|
||||
|
||||
folded := false
|
||||
if "outline" == typ {
|
||||
folded = true
|
||||
}
|
||||
|
||||
for _, root := range blockRoots {
|
||||
treeNode := &Path{
|
||||
ID: root.ID,
|
||||
|
|
@ -159,6 +164,7 @@ func toFlatTree(blocks []*Block, baseDepth int, typ string, tree *parse.Tree) (r
|
|||
SubType: root.SubType,
|
||||
Depth: baseDepth,
|
||||
Count: len(root.Children),
|
||||
Folded: folded,
|
||||
|
||||
Updated: root.IAL["updated"],
|
||||
Created: root.ID[:14],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue