Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Dec 4, 2024
2 parents 3ce968b + 4a19605 commit c77a340
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 4 additions & 0 deletions kernel/model/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func (block *Block) IsContainerBlock() bool {
return false
}

func (block *Block) IsDoc() bool {
return "NodeDocument" == block.Type
}

type Path struct {
ID string `json:"id"` // 块 ID
Box string `json:"box"` // 块 Box
Expand Down
5 changes: 4 additions & 1 deletion kernel/model/blockial.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ func setNodeAttrs0(node *ast.Node, nameValues map[string]string) (oldAttrs map[s
}

for name, value := range nameValues {
if "" == strings.TrimSpace(value) {
value = util.RemoveInvalid(value)
value = strings.TrimSpace(value)
value = strings.TrimSuffix(value, ",")
if "" == value {
node.RemoveIALAttr(name)
} else {
node.SetIALAttr(name, value)
Expand Down
19 changes: 17 additions & 2 deletions kernel/model/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ func SearchRefBlock(id, rootID, keyword string, beforeLen int, isSquareBrackets,
ret = []*Block{}
}

// 在 hPath 中加入笔记本名 Show notebooks in hpath of block ref search list results https://github.com/siyuan-note/siyuan/issues/9378
prependNotebookNameInHPath(ret)
filterSelfHPath(ret)
return
}

Expand Down Expand Up @@ -423,12 +423,25 @@ func SearchRefBlock(id, rootID, keyword string, beforeLen int, isSquareBrackets,
newDoc = true
}

// 在 hPath 中加入笔记本名 Show notebooks in hpath of block ref search list results https://github.com/siyuan-note/siyuan/issues/9378
prependNotebookNameInHPath(ret)
filterSelfHPath(ret)
return
}

func filterSelfHPath(blocks []*Block) {
// 简化搜索结果列表中的文档块路径 Simplify document block paths in search results https://github.com/siyuan-note/siyuan/issues/13364
// 文档块不显示自己的路径(最后一层)

for _, b := range blocks {
if b.IsDoc() {
b.HPath = strings.TrimSuffix(b.HPath, path.Base(b.HPath))
}
}
}

func prependNotebookNameInHPath(blocks []*Block) {
// 在 hPath 中加入笔记本名 Show notebooks in hpath of block ref search list results https://github.com/siyuan-note/siyuan/issues/9378

var boxIDs []string
for _, b := range blocks {
boxIDs = append(boxIDs, b.Box)
Expand Down Expand Up @@ -1110,6 +1123,8 @@ func FullTextSearchBlock(query string, boxes, paths []string, types map[string]b
if 1 > len(ret) {
ret = []*Block{}
}

filterSelfHPath(ret)
return
}

Expand Down

0 comments on commit c77a340

Please sign in to comment.