🎨 Virtual references exclude the name and aliases from the current document https://github.com/siyuan-note/siyuan/issues/9204

This commit is contained in:
Daniel 2023-09-17 11:15:12 +08:00
parent 58d1978eb8
commit 21aabc216d
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -56,15 +56,15 @@ func getBlockVirtualRefKeywords(root *ast.Node) (ret []string) {
return ast.WalkContinue
})
content := buf.String()
ret = putBlockVirtualRefKeywords(content, root.ID, root.IALAttr("title"))
ret = putBlockVirtualRefKeywords(content, root)
return
}
ret = val.([]string)
return
}
func putBlockVirtualRefKeywords(blockContent, blockID, docTitle string) (ret []string) {
keywords := getVirtualRefKeywords(docTitle)
func putBlockVirtualRefKeywords(blockContent string, root *ast.Node) (ret []string) {
keywords := getVirtualRefKeywords(root)
if 1 > len(keywords) {
return
}
@ -94,7 +94,7 @@ func putBlockVirtualRefKeywords(blockContent, blockID, docTitle string) (ret []s
}
ret = gulu.Str.RemoveDuplicatedElem(ret)
virtualBlockRefCache.SetWithTTL(blockID, ret, 1, 10*time.Minute)
virtualBlockRefCache.SetWithTTL(root.ID, ret, 1, 10*time.Minute)
return
}
@ -174,7 +174,7 @@ func processVirtualRef(n *ast.Node, unlinks *[]*ast.Node, virtualBlockRefKeyword
return false
}
func getVirtualRefKeywords(docName string) (ret []string) {
func getVirtualRefKeywords(root *ast.Node) (ret []string) {
if !Conf.Editor.VirtualBlockRef {
return
}
@ -225,7 +225,18 @@ func getVirtualRefKeywords(docName string) (ret []string) {
}
// 虚拟引用排除当前文档名 https://github.com/siyuan-note/siyuan/issues/4537
ret = gulu.Str.ExcludeElem(ret, []string{docName})
// Virtual references exclude the name and aliases from the current document https://github.com/siyuan-note/siyuan/issues/9204
title := root.IALAttr("title")
ret = gulu.Str.ExcludeElem(ret, []string{title})
if name := root.IALAttr("name"); "" != name {
ret = gulu.Str.ExcludeElem(ret, []string{name})
}
if alias := root.IALAttr("alias"); "" != alias {
for _, a := range strings.Split(alias, ",") {
ret = gulu.Str.ExcludeElem(ret, []string{a})
}
}
ret = prepareMarkKeywords(ret)
return
}