mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🎨 挂件搜索时过滤不相关文件 Fix https://github.com/siyuan-note/siyuan/issues/7434
This commit is contained in:
parent
014b2eab8d
commit
c917330a5d
1 changed files with 25 additions and 5 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue