A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

:art: https://github.com/siyuan-note/siyuan/issues/16206

Signed-off-by: Daniel <845765@qq.com>

Daniel fc4cadfd 3d50e401

+44 -36
-35
kernel/api/outline.go
··· 25 25 "github.com/siyuan-note/siyuan/kernel/util" 26 26 ) 27 27 28 - func getDocOutlineAndStorage(c *gin.Context) { 29 - ret := gulu.Ret.NewResult() 30 - defer c.JSON(http.StatusOK, ret) 31 - 32 - arg, ok := util.JsonArg(c, ret) 33 - if !ok { 34 - return 35 - } 36 - 37 - if nil == arg["id"] { 38 - return 39 - } 40 - preview := false 41 - if previewArg := arg["preview"]; nil != previewArg { 42 - preview = previewArg.(bool) 43 - } 44 - rootID := arg["id"].(string) 45 - data, err := model.GetOutlineStorage(rootID) 46 - if err != nil { 47 - ret.Code = -1 48 - ret.Msg = err.Error() 49 - return 50 - } 51 - headings, err := model.Outline(rootID, preview) 52 - if err != nil { 53 - ret.Code = 1 54 - ret.Msg = err.Error() 55 - return 56 - } 57 - ret.Data = map[string]any{ 58 - "headings": headings, 59 - "storage": data, 60 - } 61 - } 62 - 63 28 func getDocOutline(c *gin.Context) { 64 29 ret := gulu.Ret.NewResult() 65 30 defer c.JSON(http.StatusOK, ret)
-1
kernel/api/router.go
··· 151 151 ginServer.Handle("POST", "/api/history/getHistoryItems", model.CheckAuth, model.CheckAdminRole, getHistoryItems) 152 152 153 153 ginServer.Handle("POST", "/api/outline/getDocOutline", model.CheckAuth, getDocOutline) 154 - ginServer.Handle("POST", "/api/outline/getDocOutlineAndStorage", model.CheckAuth, getDocOutlineAndStorage) 155 154 156 155 ginServer.Handle("POST", "/api/bookmark/getBookmark", model.CheckAuth, getBookmark) 157 156 ginServer.Handle("POST", "/api/bookmark/renameBookmark", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, renameBookmark)
+1
kernel/model/block.go
··· 103 103 Children []*Path `json:"children,omitempty"` // 子路径节点 104 104 Depth int `json:"depth"` // 层级深度 105 105 Count int `json:"count"` // 子块计数 106 + Folded bool `json:"folded"` // 是否折叠 106 107 107 108 Updated string `json:"updated"` // 更新时间 108 109 Created string `json:"created"` // 创建时间
+37
kernel/model/outline.go
··· 17 17 package model 18 18 19 19 import ( 20 + "github.com/88250/gulu" 20 21 "github.com/88250/lute/ast" 21 22 "github.com/88250/lute/html" 22 23 "github.com/88250/lute/parse" ··· 236 237 } 237 238 238 239 ret = outline(tree) 240 + 241 + storage, _ := GetOutlineStorage(rootID) 242 + if nil == storage { 243 + // 默认展开顶层 244 + for _, p := range ret { 245 + p.Folded = false 246 + } 247 + } 248 + 249 + if nil != storage["expandIds"] { 250 + expandIDsArg := storage["expandIds"].([]interface{}) 251 + var expandIDs []string 252 + for _, id := range expandIDsArg { 253 + expandIDs = append(expandIDs, id.(string)) 254 + } 255 + 256 + for _, p := range ret { 257 + p.Folded = false // 顶层默认展开 258 + 259 + for _, b := range p.Blocks { 260 + b.Folded = !gulu.Str.Contains(b.ID, expandIDs) 261 + for _, c := range b.Children { 262 + walkChildren(c, expandIDs) 263 + } 264 + } 265 + } 266 + } 239 267 return 240 268 } 241 269 270 + func walkChildren(b *Block, expandIDs []string) { 271 + b.Folded = !gulu.Str.Contains(b.ID, expandIDs) 272 + for _, c := range b.Children { 273 + walkChildren(c, expandIDs) 274 + } 275 + } 276 + 242 277 func outline(tree *parse.Tree) (ret []*Path) { 243 278 luteEngine := NewLute() 244 279 var headings []*Block ··· 254 289 Content: renderOutline(n, luteEngine), 255 290 Type: n.Type.String(), 256 291 SubType: treenode.SubTypeAbbr(n), 292 + Folded: true, 257 293 } 258 294 headings = append(headings, block) 259 295 return ast.WalkSkipChildren ··· 303 339 Blocks: b.Children, 304 340 Depth: 0, 305 341 Count: b.Count, 342 + Folded: true, 306 343 }) 307 344 } 308 345 }
+6
kernel/model/path.go
··· 149 149 root.Children = append(root.Children, block) 150 150 } 151 151 152 + folded := false 153 + if "outline" == typ { 154 + folded = true 155 + } 156 + 152 157 for _, root := range blockRoots { 153 158 treeNode := &Path{ 154 159 ID: root.ID, ··· 159 164 SubType: root.SubType, 160 165 Depth: baseDepth, 161 166 Count: len(root.Children), 167 + Folded: folded, 162 168 163 169 Updated: root.IAL["updated"], 164 170 Created: root.ID[:14],