mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 The backlink panel supports filtering by the block attributes https://github.com/siyuan-note/siyuan/issues/12985
This commit is contained in:
parent
4ef73e6c6d
commit
c9cac8b08e
1 changed files with 20 additions and 11 deletions
|
|
@ -90,9 +90,7 @@ func GetBackmentionDoc(defID, refTreeID, keyword string, containChildren bool) (
|
||||||
}
|
}
|
||||||
mentionBlockIDs = gulu.Str.RemoveDuplicatedElem(mentionBlockIDs)
|
mentionBlockIDs = gulu.Str.RemoveDuplicatedElem(mentionBlockIDs)
|
||||||
|
|
||||||
if "" != keyword {
|
mentionKeywords = strings.Split(keyword, " ")
|
||||||
mentionKeywords = append(mentionKeywords, keyword)
|
|
||||||
}
|
|
||||||
mentionKeywords = gulu.Str.RemoveDuplicatedElem(mentionKeywords)
|
mentionKeywords = gulu.Str.RemoveDuplicatedElem(mentionKeywords)
|
||||||
|
|
||||||
var refTree *parse.Tree
|
var refTree *parse.Tree
|
||||||
|
|
@ -141,10 +139,7 @@ func GetBacklinkDoc(defID, refTreeID, keyword string, containChildren bool) (ret
|
||||||
|
|
||||||
luteEngine := util.NewLute()
|
luteEngine := util.NewLute()
|
||||||
for _, linkRef := range linkRefs {
|
for _, linkRef := range linkRefs {
|
||||||
var keywords []string
|
keywords := strings.Split(keyword, " ")
|
||||||
if "" != keyword {
|
|
||||||
keywords = append(keywords, keyword)
|
|
||||||
}
|
|
||||||
backlink := buildBacklink(linkRef.ID, refTree, keywords, luteEngine)
|
backlink := buildBacklink(linkRef.ID, refTree, keywords, luteEngine)
|
||||||
if nil != backlink {
|
if nil != backlink {
|
||||||
ret = append(ret, backlink)
|
ret = append(ret, backlink)
|
||||||
|
|
@ -571,8 +566,7 @@ func buildLinkRefs(defRootID string, refs []*sql.Ref, keyword string) (ret []*Bl
|
||||||
if nil != refBlock && p.FContent == refBlock.Content { // 使用内容判断是否是列表项下第一个子块
|
if nil != refBlock && p.FContent == refBlock.Content { // 使用内容判断是否是列表项下第一个子块
|
||||||
// 如果是列表项下第一个子块,则后续会通过列表项传递或关联处理,所以这里就不处理这个段落了
|
// 如果是列表项下第一个子块,则后续会通过列表项传递或关联处理,所以这里就不处理这个段落了
|
||||||
processedParagraphs.Add(p.ID)
|
processedParagraphs.Add(p.ID)
|
||||||
if !strings.Contains(p.Content, keyword) && !strings.Contains(path.Base(p.HPath), keyword) &&
|
if !matchBacklinkKeyword(p, keyword) {
|
||||||
!strings.Contains(p.Name, keyword) && !strings.Contains(p.Alias, keyword) && !strings.Contains(p.Memo, keyword) && !strings.Contains(p.Tag, keyword) {
|
|
||||||
refsCount--
|
refsCount--
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -588,8 +582,7 @@ func buildLinkRefs(defRootID string, refs []*sql.Ref, keyword string) (ret []*Bl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.Contains(ref.Content, keyword) && !strings.Contains(path.Base(ref.HPath), keyword) &&
|
if !matchBacklinkKeyword(ref, keyword) {
|
||||||
!strings.Contains(ref.Name, keyword) && !strings.Contains(ref.Alias, keyword) && !strings.Contains(ref.Memo, keyword) && !strings.Contains(ref.Tag, keyword) {
|
|
||||||
refsCount--
|
refsCount--
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -602,6 +595,22 @@ func buildLinkRefs(defRootID string, refs []*sql.Ref, keyword string) (ret []*Bl
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func matchBacklinkKeyword(block *Block, keyword string) bool {
|
||||||
|
keywords := strings.Split(keyword, " ")
|
||||||
|
for _, k := range keywords {
|
||||||
|
k = strings.ToLower(k)
|
||||||
|
if strings.Contains(strings.ToLower(block.Content), k) ||
|
||||||
|
strings.Contains(strings.ToLower(path.Base(block.HPath)), k) ||
|
||||||
|
strings.Contains(strings.ToLower(block.Name), k) ||
|
||||||
|
strings.Contains(strings.ToLower(block.Alias), k) ||
|
||||||
|
strings.Contains(strings.ToLower(block.Memo), k) ||
|
||||||
|
strings.Contains(strings.ToLower(block.Tag), k) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func removeDuplicatedRefs(refs []*sql.Ref) (ret []*sql.Ref) {
|
func removeDuplicatedRefs(refs []*sql.Ref) (ret []*sql.Ref) {
|
||||||
// 同一个块中引用多个块后反链去重
|
// 同一个块中引用多个块后反链去重
|
||||||
// De-duplication of backlinks after referencing multiple blocks in the same block https://github.com/siyuan-note/siyuan/issues/12147
|
// De-duplication of backlinks after referencing multiple blocks in the same block https://github.com/siyuan-note/siyuan/issues/12147
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue