From d19cd19f44f1b522781dcfd5a27366f8c6b88be5 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sun, 2 Oct 2022 11:27:56 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E7=BC=96=E8=BE=91=E5=99=A8?= =?UTF-8?q?=E5=BC=8F=E5=8F=8D=E9=93=BE=E9=9D=A2=E6=9D=BF=20https://github.?= =?UTF-8?q?com/siyuan-note/siyuan/issues/3565?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/backlink.go | 8 +++++++- kernel/model/path.go | 44 ---------------------------------------- 2 files changed, 7 insertions(+), 45 deletions(-) diff --git a/kernel/model/backlink.go b/kernel/model/backlink.go index 2e1bf2d06..a5a84b2f1 100644 --- a/kernel/model/backlink.go +++ b/kernel/model/backlink.go @@ -397,10 +397,16 @@ func BuildTreeBacklink(id, keyword, mentionKeyword string, beforeLen int) (boxID refs = removeDuplicatedRefs(refs) // 同一个块中引用多个相同块时反链去重 https://github.com/siyuan-note/siyuan/issues/3317 linkRefs, excludeBacklinkIDs := buildLinkRefs(id, refs) - backlinks = toSubTree(linkRefs, keyword) + backlinks = toFlatTree(linkRefs, 0, "backlink") + for _, l := range backlinks { + l.Blocks = nil + } mentionRefs := buildTreeBackmention(sqlBlock, linkRefs, mentionKeyword, excludeBacklinkIDs, beforeLen) backmentions = toFlatTree(mentionRefs, 0, "backlink") + for _, l := range backmentions { + l.Blocks = nil + } mentionsCount = len(backmentions) return } diff --git a/kernel/model/path.go b/kernel/model/path.go index 37c89b1c7..4f754c99d 100644 --- a/kernel/model/path.go +++ b/kernel/model/path.go @@ -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