🎨 Improve backlink filtering below the heading https://github.com/siyuan-note/siyuan/issues/14929

This commit is contained in:
Daniel 2025-05-29 21:02:04 +08:00
parent 84e9a003e8
commit c2c4c2393f
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -656,6 +656,38 @@ func buildLinkRefs(defRootID string, refs []*sql.Ref, keywords []string) (ret []
ret = append(ret, ref)
}
}
if 0 < len(keywords) {
// 过滤场景处理标题下方块 Improve backlink filtering below the heading https://github.com/siyuan-note/siyuan/issues/14929
headingRefChildren := map[string]*Block{}
var headingIDs []string
for _, link := range links {
for _, ref := range link.Refs {
if "NodeHeading" == ref.Type {
headingRefChildren[ref.ID] = ref
headingIDs = append(headingIDs, ref.ID)
}
}
}
var headingChildren []*Block
for _, headingID := range headingIDs {
sqlChildren := sql.GetChildBlocks(headingID, "", -1)
children := fromSQLBlocks(&sqlChildren, "", 12)
headingChildren = append(headingChildren, children...)
}
for _, child := range headingChildren {
if nil == child {
continue
}
if matchBacklinkKeyword(child, keywords) {
heading := headingRefChildren[child.ParentID]
if nil != heading {
ret = append(ret, heading)
}
}
}
}
return
}