This commit is contained in:
Liang Ding 2022-10-02 12:00:55 +08:00
parent ab8b70d78d
commit 17595a3076
No known key found for this signature in database
GPG key ID: 136F30F901A2231D

View file

@ -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