mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 15:10:12 +01:00
🎨 Support search code snippets https://github.com/siyuan-note/siyuan/issues/10739
This commit is contained in:
parent
10c181659d
commit
8eb718d578
1 changed files with 15 additions and 0 deletions
|
|
@ -70,6 +70,10 @@ func getSnippet(c *gin.Context) {
|
||||||
if 0 == enabledArg {
|
if 0 == enabledArg {
|
||||||
enabled = false
|
enabled = false
|
||||||
}
|
}
|
||||||
|
var keyword string
|
||||||
|
if nil != arg["keyword"] {
|
||||||
|
keyword = arg["keyword"].(string)
|
||||||
|
}
|
||||||
|
|
||||||
confSnippets, err := model.LoadSnippets()
|
confSnippets, err := model.LoadSnippets()
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
@ -84,6 +88,17 @@ func getSnippet(c *gin.Context) {
|
||||||
snippets = append(snippets, s)
|
snippets = append(snippets, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if "" != keyword {
|
||||||
|
var snippetsFiltered []*conf.Snippet
|
||||||
|
for _, s := range snippets {
|
||||||
|
if strings.Contains(strings.ToLower(s.Name), strings.ToLower(keyword)) || strings.Contains(strings.ToLower(s.Content), strings.ToLower(keyword)) {
|
||||||
|
snippetsFiltered = append(snippetsFiltered, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
snippets = snippetsFiltered
|
||||||
|
}
|
||||||
|
|
||||||
if 1 > len(snippets) {
|
if 1 > len(snippets) {
|
||||||
snippets = []*conf.Snippet{}
|
snippets = []*conf.Snippet{}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue