From 17595a3076fdb879dc4b7c8efd373b31bb11217b Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sun, 2 Oct 2022 12:00:55 +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 | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/kernel/model/backlink.go b/kernel/model/backlink.go index 27b8b4361..8586aa349 100644 --- a/kernel/model/backlink.go +++ b/kernel/model/backlink.go @@ -298,6 +298,8 @@ func buildBacklink(refID string, refTree *parse.Tree, luteEngine *lute.Lute) (re } func BuildTreeBacklink(id, keyword, mentionKeyword string, beforeLen int) (boxID string, backlinks, backmentions []*Path, linkRefsCount, mentionsCount int) { + keyword = strings.TrimSpace(keyword) + mentionKeyword = strings.TrimSpace(mentionKeyword) backlinks, backmentions = []*Path{}, []*Path{} sqlBlock := sql.GetBlock(id) @@ -310,15 +312,27 @@ func BuildTreeBacklink(id, keyword, mentionKeyword string, beforeLen int) (boxID refs = removeDuplicatedRefs(refs) // 同一个块中引用多个相同块时反链去重 https://github.com/siyuan-note/siyuan/issues/3317 linkRefs, linkRefsCount, excludeBacklinkIDs := buildLinkRefs(id, refs) - backlinks = toFlatTree(linkRefs, 0, "backlink") - for _, l := range backlinks { + tmpBacklinks := toFlatTree(linkRefs, 0, "backlink") + for _, l := range tmpBacklinks { l.Blocks = nil + if "" != keyword { + if !strings.Contains(l.Name, keyword) { + continue + } + } + backlinks = append(backlinks, l) } mentionRefs := buildTreeBackmention(sqlBlock, linkRefs, mentionKeyword, excludeBacklinkIDs, beforeLen) - backmentions = toFlatTree(mentionRefs, 0, "backlink") - for _, l := range backmentions { + tmpBackmentions := toFlatTree(mentionRefs, 0, "backlink") + for _, l := range tmpBackmentions { l.Blocks = nil + if "" != mentionKeyword { + if !strings.Contains(l.Name, mentionKeyword) { + continue + } + } + backmentions = append(backmentions, l) } mentionsCount = len(backmentions) return