Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2024-11-03 11:16:40 +08:00
commit b3bc642e07
6 changed files with 46 additions and 10 deletions

File diff suppressed because one or more lines are too long

View file

@ -10,7 +10,7 @@ require (
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7
github.com/88250/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02
github.com/88250/lute v1.7.7-0.20241102053749-a0880752c7a4
github.com/88250/lute v1.7.7-0.20241103012411-a8a9e2f09aa7
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
github.com/ClarkThan/ahocorasick v0.0.0-20231011042242-30d1ef1347f4

View file

@ -14,8 +14,8 @@ github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950 h1:Pa5hMiBceT
github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/88250/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02 h1:3e5+yobj655pTeKOYMbJrnc1mE51ZkbXIxquTYZuYCY=
github.com/88250/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02/go.mod h1:MUfzyfmbPrRDZLqxc7aPrVYveatTHRfoUa5TynPS0i8=
github.com/88250/lute v1.7.7-0.20241102053749-a0880752c7a4 h1:LEDeXpgAjr4Sy5l2Ap1g/u7fZSRFimNtNtSO3MXvrt4=
github.com/88250/lute v1.7.7-0.20241102053749-a0880752c7a4/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
github.com/88250/lute v1.7.7-0.20241103012411-a8a9e2f09aa7 h1:RYL3C4DRTBZpa2JVCTcekFJ/+ECil5eAVTt3Np1msa8=
github.com/88250/lute v1.7.7-0.20241103012411-a8a9e2f09aa7/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=

View file

@ -58,6 +58,8 @@ type Backlink struct {
DOM string `json:"dom"`
BlockPaths []*BlockPath `json:"blockPaths"`
Expand bool `json:"expand"`
node *ast.Node // 仅用于按文档内容顺序排序
}
func GetBackmentionDoc(defID, refTreeID, keyword string, containChildren bool) (ret []*Backlink) {
@ -93,12 +95,20 @@ func GetBackmentionDoc(defID, refTreeID, keyword string, containChildren bool) (
}
mentionKeywords = gulu.Str.RemoveDuplicatedElem(mentionKeywords)
var refTree *parse.Tree
trees := filesys.LoadTrees(mentionBlockIDs)
for id, tree := range trees {
backlink := buildBacklink(id, tree, mentionKeywords, luteEngine)
if nil != backlink {
ret = append(ret, backlink)
}
if nil != tree && nil == refTree {
refTree = tree
}
}
if 0 < len(trees) {
sortBacklinks(ret, refTree)
}
return
}
@ -139,9 +149,31 @@ func GetBacklinkDoc(defID, refTreeID, keyword string, containChildren bool) (ret
ret = append(ret, backlink)
}
}
sortBacklinks(ret, refTree)
return
}
func sortBacklinks(backlinks []*Backlink, tree *parse.Tree) {
contentSorts := map[string]int{}
sortVal := 0
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering || !n.IsBlock() {
return ast.WalkContinue
}
contentSorts[n.ID] = sortVal
sortVal++
return ast.WalkContinue
})
sort.Slice(backlinks, func(i, j int) bool {
s1 := contentSorts[backlinks[i].node.ID]
s2 := contentSorts[backlinks[j].node.ID]
return s1 < s2
})
}
func buildBacklink(refID string, refTree *parse.Tree, keywords []string, luteEngine *lute.Lute) (ret *Backlink) {
n := treenode.GetNodeInTree(refTree, refID)
if nil == n {
@ -175,12 +207,13 @@ func buildBacklink(refID string, refTree *parse.Tree, keywords []string, luteEng
dom := renderBlockDOMByNodes(renderNodes, luteEngine)
blockPaths := []*BlockPath{}
if nil != n.Parent && ast.NodeDocument != n.Parent.Type && nil != n.Parent.Parent && ast.NodeDocument != n.Parent.Parent.Type {
if (nil != n.Parent && ast.NodeDocument != n.Parent.Type && nil != n.Parent.Parent && ast.NodeDocument != n.Parent.Parent.Type) || nil != treenode.HeadingParent(n) {
// 仅在多于一层时才显示面包屑,这样界面展示更加简洁
// The backlink panel no longer displays breadcrumbs of the first-level blocks https://github.com/siyuan-note/siyuan/issues/12862
// Improve the backlink panel breadcrumb and block sorting https://github.com/siyuan-note/siyuan/issues/13008
blockPaths = buildBlockBreadcrumb(n, nil, false)
}
ret = &Backlink{DOM: dom, BlockPaths: blockPaths, Expand: expand}
ret = &Backlink{DOM: dom, BlockPaths: blockPaths, Expand: expand, node: n}
return
}

View file

@ -507,6 +507,11 @@ func buildBlockBreadcrumb(node *ast.Node, excludeTypes []string, displayCurrentN
}
if ast.NodeHeading == b.Type && headingLevel > b.HeadingLevel {
if b.ParentIs(ast.NodeListItem) {
// 标题在列表下时不显示 https://github.com/siyuan-note/siyuan/issues/13008
continue
}
name = gulu.Str.SubStr(renderBlockText(b, excludeTypes), maxNameLen)
name = util.EscapeHTML(name)
ret = append([]*BlockPath{{

View file

@ -1329,7 +1329,6 @@ func fullTextSearchCountByRegexp(exp, boxFilter, pathFilter, typeFilter, ignoreF
}
func fullTextSearchByFTS(query, boxFilter, pathFilter, typeFilter, ignoreFilter, orderBy string, beforeLen, page, pageSize int) (ret []*Block, matchedBlockCount, matchedRootCount int) {
start := time.Now()
query = stringQuery(query)
table := "blocks_fts" // 大小写敏感
if !Conf.Search.CaseSensitive {
@ -1355,7 +1354,6 @@ func fullTextSearchByFTS(query, boxFilter, pathFilter, typeFilter, ignoreFilter,
}
matchedBlockCount, matchedRootCount = fullTextSearchCountByFTS(query, boxFilter, pathFilter, typeFilter, ignoreFilter)
logging.LogInfof("time cost [fts]: %v", time.Since(start))
return
}