mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 反链面板支持文档排序 https://github.com/siyuan-note/insider/issues/1086
This commit is contained in:
parent
7388c0d2a7
commit
e34e7fe217
4 changed files with 64 additions and 3 deletions
|
|
@ -89,7 +89,17 @@ func getBacklink2(c *gin.Context) {
|
||||||
id := arg["id"].(string)
|
id := arg["id"].(string)
|
||||||
keyword := arg["k"].(string)
|
keyword := arg["k"].(string)
|
||||||
mentionKeyword := arg["mk"].(string)
|
mentionKeyword := arg["mk"].(string)
|
||||||
boxID, backlinks, backmentions, linkRefsCount, mentionsCount := model.GetBacklink2(id, keyword, mentionKeyword)
|
sortArg := arg["sort"]
|
||||||
|
sort := util.SortModeUpdatedDESC
|
||||||
|
if nil != sortArg {
|
||||||
|
sort = int(sortArg.(float64))
|
||||||
|
}
|
||||||
|
mentionSortArg := arg["msort"]
|
||||||
|
mentionSort := util.SortModeUpdatedDESC
|
||||||
|
if nil != mentionSortArg {
|
||||||
|
sort = int(mentionSortArg.(float64))
|
||||||
|
}
|
||||||
|
boxID, backlinks, backmentions, linkRefsCount, mentionsCount := model.GetBacklink2(id, keyword, mentionKeyword, sort, mentionSort)
|
||||||
ret.Data = map[string]interface{}{
|
ret.Data = map[string]interface{}{
|
||||||
"backlinks": backlinks,
|
"backlinks": backlinks,
|
||||||
"linkRefsCount": linkRefsCount,
|
"linkRefsCount": linkRefsCount,
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ import (
|
||||||
"github.com/88250/lute/ast"
|
"github.com/88250/lute/ast"
|
||||||
"github.com/88250/lute/parse"
|
"github.com/88250/lute/parse"
|
||||||
"github.com/emirpasic/gods/sets/hashset"
|
"github.com/emirpasic/gods/sets/hashset"
|
||||||
|
"github.com/facette/natsort"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
"github.com/siyuan-note/siyuan/kernel/search"
|
"github.com/siyuan-note/siyuan/kernel/search"
|
||||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||||
|
|
@ -299,7 +300,7 @@ func buildBacklink(refID string, refTree *parse.Tree, luteEngine *lute.Lute) (re
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBacklink2(id, keyword, mentionKeyword string) (boxID string, backlinks, backmentions []*Path, linkRefsCount, mentionsCount int) {
|
func GetBacklink2(id, keyword, mentionKeyword string, sortMode, mentionSortMode int) (boxID string, backlinks, backmentions []*Path, linkRefsCount, mentionsCount int) {
|
||||||
keyword = strings.TrimSpace(keyword)
|
keyword = strings.TrimSpace(keyword)
|
||||||
mentionKeyword = strings.TrimSpace(mentionKeyword)
|
mentionKeyword = strings.TrimSpace(mentionKeyword)
|
||||||
backlinks, backmentions = []*Path{}, []*Path{}
|
backlinks, backmentions = []*Path{}, []*Path{}
|
||||||
|
|
@ -326,6 +327,28 @@ func GetBacklink2(id, keyword, mentionKeyword string) (boxID string, backlinks,
|
||||||
backlinks = append(backlinks, l)
|
backlinks = append(backlinks, l)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Slice(backlinks, func(i, j int) bool {
|
||||||
|
switch sortMode {
|
||||||
|
case util.SortModeUpdatedDESC:
|
||||||
|
return backlinks[i].Updated > backlinks[j].Updated
|
||||||
|
case util.SortModeUpdatedASC:
|
||||||
|
return backlinks[i].Updated < backlinks[j].Updated
|
||||||
|
case util.SortModeCreatedDESC:
|
||||||
|
return backlinks[i].Created > backlinks[j].Created
|
||||||
|
case util.SortModeCreatedASC:
|
||||||
|
return backlinks[i].Created < backlinks[j].Created
|
||||||
|
case util.SortModeNameDESC:
|
||||||
|
return util.PinYinCompare(util.RemoveEmoji(backlinks[j].Name), util.RemoveEmoji(backlinks[i].Name))
|
||||||
|
case util.SortModeNameASC:
|
||||||
|
return util.PinYinCompare(util.RemoveEmoji(backlinks[i].Name), util.RemoveEmoji(backlinks[j].Name))
|
||||||
|
case util.SortModeAlphanumDESC:
|
||||||
|
return natsort.Compare(util.RemoveEmoji(backlinks[j].Name), util.RemoveEmoji(backlinks[i].Name))
|
||||||
|
case util.SortModeAlphanumASC:
|
||||||
|
return natsort.Compare(util.RemoveEmoji(backlinks[i].Name), util.RemoveEmoji(backlinks[j].Name))
|
||||||
|
}
|
||||||
|
return backlinks[i].ID > backlinks[j].ID
|
||||||
|
})
|
||||||
|
|
||||||
mentionRefs := buildTreeBackmention(sqlBlock, linkRefs, mentionKeyword, excludeBacklinkIDs, 12)
|
mentionRefs := buildTreeBackmention(sqlBlock, linkRefs, mentionKeyword, excludeBacklinkIDs, 12)
|
||||||
tmpBackmentions := toFlatTree(mentionRefs, 0, "backlink")
|
tmpBackmentions := toFlatTree(mentionRefs, 0, "backlink")
|
||||||
for _, l := range tmpBackmentions {
|
for _, l := range tmpBackmentions {
|
||||||
|
|
@ -337,6 +360,29 @@ func GetBacklink2(id, keyword, mentionKeyword string) (boxID string, backlinks,
|
||||||
}
|
}
|
||||||
backmentions = append(backmentions, l)
|
backmentions = append(backmentions, l)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Slice(backmentions, func(i, j int) bool {
|
||||||
|
switch sortMode {
|
||||||
|
case util.SortModeUpdatedDESC:
|
||||||
|
return backmentions[i].Updated > backmentions[j].Updated
|
||||||
|
case util.SortModeUpdatedASC:
|
||||||
|
return backmentions[i].Updated < backmentions[j].Updated
|
||||||
|
case util.SortModeCreatedDESC:
|
||||||
|
return backmentions[i].Created > backmentions[j].Created
|
||||||
|
case util.SortModeCreatedASC:
|
||||||
|
return backmentions[i].Created < backmentions[j].Created
|
||||||
|
case util.SortModeNameDESC:
|
||||||
|
return util.PinYinCompare(util.RemoveEmoji(backmentions[j].Name), util.RemoveEmoji(backmentions[i].Name))
|
||||||
|
case util.SortModeNameASC:
|
||||||
|
return util.PinYinCompare(util.RemoveEmoji(backmentions[i].Name), util.RemoveEmoji(backmentions[j].Name))
|
||||||
|
case util.SortModeAlphanumDESC:
|
||||||
|
return natsort.Compare(util.RemoveEmoji(backmentions[j].Name), util.RemoveEmoji(backmentions[i].Name))
|
||||||
|
case util.SortModeAlphanumASC:
|
||||||
|
return natsort.Compare(util.RemoveEmoji(backmentions[i].Name), util.RemoveEmoji(backmentions[j].Name))
|
||||||
|
}
|
||||||
|
return backmentions[i].ID > backmentions[j].ID
|
||||||
|
})
|
||||||
|
|
||||||
mentionsCount = len(backmentions)
|
mentionsCount = len(backmentions)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,9 @@ type Path struct {
|
||||||
Children []*Path `json:"children,omitempty"` // 子路径节点
|
Children []*Path `json:"children,omitempty"` // 子路径节点
|
||||||
Depth int `json:"depth"` // 层级深度
|
Depth int `json:"depth"` // 层级深度
|
||||||
Count int `json:"count"` // 子块计数
|
Count int `json:"count"` // 子块计数
|
||||||
|
|
||||||
|
Updated string `json:"updated"` // 更新时间
|
||||||
|
Created string `json:"created"` // 创建时间
|
||||||
}
|
}
|
||||||
|
|
||||||
func RecentUpdatedBlocks() (ret []*Block) {
|
func RecentUpdatedBlocks() (ret []*Block) {
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,9 @@ func toFlatTree(blocks []*Block, baseDepth int, typ string) (ret []*Path) {
|
||||||
SubType: root.SubType,
|
SubType: root.SubType,
|
||||||
Depth: baseDepth,
|
Depth: baseDepth,
|
||||||
Count: len(root.Children),
|
Count: len(root.Children),
|
||||||
|
|
||||||
|
Updated: root.IAL["updated"],
|
||||||
|
Created: root.ID[:14],
|
||||||
}
|
}
|
||||||
for _, c := range root.Children {
|
for _, c := range root.Children {
|
||||||
treeNode.Blocks = append(treeNode.Blocks, c)
|
treeNode.Blocks = append(treeNode.Blocks, c)
|
||||||
|
|
@ -125,7 +128,6 @@ func toFlatTree(blocks []*Block, baseDepth int, typ string) (ret []*Path) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func toSubTree(blocks []*Block, keyword string) (ret []*Path) {
|
func toSubTree(blocks []*Block, keyword string) (ret []*Path) {
|
||||||
keyword = strings.TrimSpace(keyword)
|
keyword = strings.TrimSpace(keyword)
|
||||||
var blockRoots []*Block
|
var blockRoots []*Block
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue