mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
This commit is contained in:
parent
fcaddd6966
commit
d19cd19f44
2 changed files with 7 additions and 45 deletions
|
|
@ -27,7 +27,6 @@ import (
|
|||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/search"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
|
@ -124,49 +123,6 @@ func toFlatTree(blocks []*Block, baseDepth int, typ string) (ret []*Path) {
|
|||
return
|
||||
}
|
||||
|
||||
func toSubTree(blocks []*Block, keyword string) (ret []*Path) {
|
||||
keyword = strings.TrimSpace(keyword)
|
||||
var blockRoots []*Block
|
||||
for _, block := range blocks {
|
||||
root := getBlockIn(blockRoots, block.RootID)
|
||||
if nil == root {
|
||||
root, _ = getBlock(block.RootID)
|
||||
blockRoots = append(blockRoots, root)
|
||||
}
|
||||
block.Depth = 1
|
||||
block.Count = len(block.Children)
|
||||
root.Children = append(root.Children, block)
|
||||
}
|
||||
|
||||
for _, root := range blockRoots {
|
||||
treeNode := &Path{
|
||||
ID: root.ID,
|
||||
Box: root.Box,
|
||||
Name: path.Base(root.HPath),
|
||||
Type: "backlink",
|
||||
NodeType: "NodeDocument",
|
||||
SubType: root.SubType,
|
||||
Depth: 0,
|
||||
Count: len(root.Children),
|
||||
}
|
||||
|
||||
rootPos := -1
|
||||
var rootContent string
|
||||
if "" != keyword {
|
||||
rootPos, rootContent = search.MarkText(treeNode.Name, keyword, 12, Conf.Search.CaseSensitive)
|
||||
treeNode.Name = rootContent
|
||||
}
|
||||
if 0 < len(treeNode.Children) || 0 < len(treeNode.Blocks) || (-1 < rootPos && "" != keyword) {
|
||||
ret = append(ret, treeNode)
|
||||
}
|
||||
}
|
||||
|
||||
sort.Slice(ret, func(i, j int) bool {
|
||||
return ret[i].ID > ret[j].ID
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func getBlockIn(blocks []*Block, id string) *Block {
|
||||
if "" == id {
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue