Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2023-02-21 18:58:06 +08:00
commit c65a88db88

View file

@ -29,23 +29,43 @@ import (
func SearchWidget(keyword string) (ret []*Block) {
ret = []*Block{}
widgets := filepath.Join(util.DataDir, "widgets")
dirs, err := os.ReadDir(widgets)
entries, err := os.ReadDir(widgets)
if nil != err {
logging.LogErrorf("read dir [%s] failed: %s", widgets, err)
return
}
k := strings.ToLower(keyword)
for _, dir := range dirs {
name := strings.ToLower(dir.Name())
for _, entry := range entries {
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, ".") {
continue
}
if strings.Contains(name, k) {
name = dir.Name()
name = entry.Name()
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}
ret = append(ret, b)