mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-03 04:31:50 +08:00
🎨 Improve backmention highlighting https://github.com/siyuan-note/siyuan/issues/13328
This commit is contained in:
parent
441b6f7f65
commit
8f89caf22e
@ -60,9 +60,10 @@ func getBackmentionDoc(c *gin.Context) {
|
|||||||
if val, ok := arg["highlight"]; ok {
|
if val, ok := arg["highlight"]; ok {
|
||||||
highlight = val.(bool)
|
highlight = val.(bool)
|
||||||
}
|
}
|
||||||
backlinks := model.GetBackmentionDoc(defID, refTreeID, keyword, containChildren, highlight)
|
backlinks, keywords := model.GetBackmentionDoc(defID, refTreeID, keyword, containChildren, highlight)
|
||||||
ret.Data = map[string]interface{}{
|
ret.Data = map[string]interface{}{
|
||||||
"backmentions": backlinks,
|
"backmentions": backlinks,
|
||||||
|
"keywords": keywords,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,9 +87,10 @@ func getBacklinkDoc(c *gin.Context) {
|
|||||||
if val, ok := arg["highlight"]; ok {
|
if val, ok := arg["highlight"]; ok {
|
||||||
highlight = val.(bool)
|
highlight = val.(bool)
|
||||||
}
|
}
|
||||||
backlinks := model.GetBacklinkDoc(defID, refTreeID, keyword, containChildren, highlight)
|
backlinks, keywords := model.GetBacklinkDoc(defID, refTreeID, keyword, containChildren, highlight)
|
||||||
ret.Data = map[string]interface{}{
|
ret.Data = map[string]interface{}{
|
||||||
"backlinks": backlinks,
|
"backlinks": backlinks,
|
||||||
|
"keywords": keywords,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,8 +62,7 @@ type Backlink struct {
|
|||||||
node *ast.Node // 仅用于按文档内容顺序排序
|
node *ast.Node // 仅用于按文档内容顺序排序
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBackmentionDoc(defID, refTreeID, keyword string, containChildren, highlight bool) (ret []*Backlink) {
|
func GetBackmentionDoc(defID, refTreeID, keyword string, containChildren, highlight bool) (ret []*Backlink, keywords []string) {
|
||||||
var keywords []string
|
|
||||||
keyword = strings.TrimSpace(keyword)
|
keyword = strings.TrimSpace(keyword)
|
||||||
if "" != keyword {
|
if "" != keyword {
|
||||||
keywords = strings.Split(keyword, " ")
|
keywords = strings.Split(keyword, " ")
|
||||||
@ -98,6 +97,11 @@ func GetBackmentionDoc(defID, refTreeID, keyword string, containChildren, highli
|
|||||||
mentionKeywords = append(mentionKeywords, strings.Split(keyword, " ")...)
|
mentionKeywords = append(mentionKeywords, strings.Split(keyword, " ")...)
|
||||||
}
|
}
|
||||||
mentionKeywords = gulu.Str.RemoveDuplicatedElem(mentionKeywords)
|
mentionKeywords = gulu.Str.RemoveDuplicatedElem(mentionKeywords)
|
||||||
|
keywords = append(keywords, mentionKeywords...)
|
||||||
|
keywords = gulu.Str.RemoveDuplicatedElem(keywords)
|
||||||
|
if 1 > len(keywords) {
|
||||||
|
keywords = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
var refTree *parse.Tree
|
var refTree *parse.Tree
|
||||||
trees := filesys.LoadTrees(mentionBlockIDs)
|
trees := filesys.LoadTrees(mentionBlockIDs)
|
||||||
@ -118,12 +122,15 @@ func GetBackmentionDoc(defID, refTreeID, keyword string, containChildren, highli
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBacklinkDoc(defID, refTreeID, keyword string, containChildren, highlight bool) (ret []*Backlink) {
|
func GetBacklinkDoc(defID, refTreeID, keyword string, containChildren, highlight bool) (ret []*Backlink, keywords []string) {
|
||||||
var keywords []string
|
|
||||||
keyword = strings.TrimSpace(keyword)
|
keyword = strings.TrimSpace(keyword)
|
||||||
if "" != keyword {
|
if "" != keyword {
|
||||||
keywords = strings.Split(keyword, " ")
|
keywords = strings.Split(keyword, " ")
|
||||||
}
|
}
|
||||||
|
keywords = gulu.Str.RemoveDuplicatedElem(keywords)
|
||||||
|
if 1 > len(keywords) {
|
||||||
|
keywords = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
ret = []*Backlink{}
|
ret = []*Backlink{}
|
||||||
sqlBlock := sql.GetBlock(defID)
|
sqlBlock := sql.GetBlock(defID)
|
||||||
|
Loading…
Reference in New Issue
Block a user