An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: 反链面板支持文档排序 https://github.com/siyuan-note/insider/issues/1086
Liang Dinge34e7fe2174f
diff --git a/kernel/api/ref.go b/kernel/api/ref.goindex 682b76fa82..a33ad83d0a 100644--- a/kernel/api/ref.go+++ b/kernel/api/ref.go@@ -89,7 +89,17 @@ func getBacklink2(c *gin.Context) {id := arg["id"].(string)keyword := arg["k"].(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{}{"backlinks": backlinks,"linkRefsCount": linkRefsCount,diff --git a/kernel/model/backlink.go b/kernel/model/backlink.goindex 92ea0f07f4..095b422fc2 100644--- a/kernel/model/backlink.go+++ b/kernel/model/backlink.go@@ -30,6 +30,7 @@ import ("github.com/88250/lute/ast""github.com/88250/lute/parse""github.com/emirpasic/gods/sets/hashset"+ "github.com/facette/natsort""github.com/siyuan-note/logging""github.com/siyuan-note/siyuan/kernel/search""github.com/siyuan-note/siyuan/kernel/sql"@@ -299,7 +300,7 @@ func buildBacklink(refID string, refTree *parse.Tree, luteEngine *lute.Lute) (rereturn}-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)mentionKeyword = strings.TrimSpace(mentionKeyword)backlinks, backmentions = []*Path{}, []*Path{}@@ -326,6 +327,28 @@ func GetBacklink2(id, keyword, mentionKeyword string) (boxID string, backlinks,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)tmpBackmentions := toFlatTree(mentionRefs, 0, "backlink")for _, l := range tmpBackmentions {@@ -337,6 +360,29 @@ func GetBacklink2(id, keyword, mentionKeyword string) (boxID string, backlinks,}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)return}diff --git a/kernel/model/block.go b/kernel/model/block.goindex e9a10e2308..c99d5f55ab 100644--- a/kernel/model/block.go+++ b/kernel/model/block.go@@ -76,6 +76,9 @@ type Path struct {Children []*Path `json:"children,omitempty"` // 子路径节点Depth int `json:"depth"` // 层级深度Count int `json:"count"` // 子块计数++ Updated string `json:"updated"` // 更新时间+ Created string `json:"created"` // 创建时间}func RecentUpdatedBlocks() (ret []*Block) {diff --git a/kernel/model/path.go b/kernel/model/path.goindex d67b2fa642..7f3193e161 100644--- a/kernel/model/path.go+++ b/kernel/model/path.go@@ -112,6 +112,9 @@ func toFlatTree(blocks []*Block, baseDepth int, typ string) (ret []*Path) {SubType: root.SubType,Depth: baseDepth,Count: len(root.Children),++ Updated: root.IAL["updated"],+ Created: root.ID[:14],}for _, c := range root.Children {treeNode.Blocks = append(treeNode.Blocks, c)@@ -125,7 +128,6 @@ func toFlatTree(blocks []*Block, baseDepth int, typ string) (ret []*Path) {return}-func toSubTree(blocks []*Block, keyword string) (ret []*Path) {keyword = strings.TrimSpace(keyword)var blockRoots []*Block