mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-19 02:21:38 +08:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
c65a88db88
@ -29,23 +29,43 @@ import (
|
|||||||
func SearchWidget(keyword string) (ret []*Block) {
|
func SearchWidget(keyword string) (ret []*Block) {
|
||||||
ret = []*Block{}
|
ret = []*Block{}
|
||||||
widgets := filepath.Join(util.DataDir, "widgets")
|
widgets := filepath.Join(util.DataDir, "widgets")
|
||||||
dirs, err := os.ReadDir(widgets)
|
entries, err := os.ReadDir(widgets)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logging.LogErrorf("read dir [%s] failed: %s", widgets, err)
|
logging.LogErrorf("read dir [%s] failed: %s", widgets, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
k := strings.ToLower(keyword)
|
k := strings.ToLower(keyword)
|
||||||
for _, dir := range dirs {
|
for _, entry := range entries {
|
||||||
name := strings.ToLower(dir.Name())
|
if !entry.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
isWidgetDir := false
|
||||||
|
subEntries, readErr := os.ReadDir(filepath.Join(widgets, entry.Name()))
|
||||||
|
if nil != readErr {
|
||||||
|
logging.LogWarnf("read dir [%s] failed: %s", filepath.Join(widgets, entry.Name()), readErr)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, subEntry := range subEntries {
|
||||||
|
if !subEntry.IsDir() && "widget.json" == subEntry.Name() {
|
||||||
|
isWidgetDir = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !isWidgetDir {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
name := strings.ToLower(entry.Name())
|
||||||
if strings.HasPrefix(name, ".") {
|
if strings.HasPrefix(name, ".") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(name, k) {
|
if strings.Contains(name, k) {
|
||||||
name = dir.Name()
|
name = entry.Name()
|
||||||
if "" != keyword {
|
if "" != keyword {
|
||||||
_, name = search.MarkText(dir.Name(), keyword, 32, Conf.Search.CaseSensitive)
|
_, name = search.MarkText(entry.Name(), keyword, 32, Conf.Search.CaseSensitive)
|
||||||
}
|
}
|
||||||
b := &Block{Content: name}
|
b := &Block{Content: name}
|
||||||
ret = append(ret, b)
|
ret = append(ret, b)
|
||||||
|
Loading…
Reference in New Issue
Block a user