Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2025-10-28 20:36:35 +08:00
parent 3d50e40177
commit fc4cadfd58
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
5 changed files with 44 additions and 36 deletions

View file

@ -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"` // 创建时间

View file

@ -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,
})
}
}

View file

@ -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],