mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-03 23:38:49 +01:00
🧑💻 Add internal kernel API /api/block/getBlocksIndexes Fix https://github.com/siyuan-note/siyuan/issues/10608
This commit is contained in:
parent
0daa752ba9
commit
095dfc2b35
3 changed files with 52 additions and 0 deletions
|
|
@ -274,6 +274,39 @@ func GetBlockIndex(id string) (ret int) {
|
|||
return
|
||||
}
|
||||
|
||||
func GetBlocksIndexes(ids []string) (ret map[string]int) {
|
||||
ret = map[string]int{}
|
||||
if 1 > len(ids) {
|
||||
return
|
||||
}
|
||||
|
||||
tree, _ := LoadTreeByBlockID(ids[0])
|
||||
if nil == tree {
|
||||
return
|
||||
}
|
||||
|
||||
idx := 0
|
||||
nodesIndexes := map[string]int{}
|
||||
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
if !entering {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
if !n.IsChildBlockOf(tree.Root, 1) {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
nodesIndexes[n.ID] = idx
|
||||
idx++
|
||||
return ast.WalkContinue
|
||||
})
|
||||
|
||||
for _, id := range ids {
|
||||
ret[id] = nodesIndexes[id]
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type BlockPath struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue