A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
at lambda-fork/main 66 lines 1.7 kB view raw
1// SiYuan - Refactor your thinking 2// Copyright (c) 2020-present, b3log.org 3// 4// This program is free software: you can redistribute it and/or modify 5// it under the terms of the GNU Affero General Public License as published by 6// the Free Software Foundation, either version 3 of the License, or 7// (at your option) any later version. 8// 9// This program is distributed in the hope that it will be useful, 10// but WITHOUT ANY WARRANTY; without even the implied warranty of 11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12// GNU Affero General Public License for more details. 13// 14// You should have received a copy of the GNU Affero General Public License 15// along with this program. If not, see <https://www.gnu.org/licenses/>. 16 17package model 18 19import ( 20 "os" 21 "path/filepath" 22 "strings" 23 24 "github.com/siyuan-note/logging" 25 "github.com/siyuan-note/siyuan/kernel/bazaar" 26 "github.com/siyuan-note/siyuan/kernel/util" 27) 28 29func SearchWidget(keyword string) (ret []*Block) { 30 ret = []*Block{} 31 widgetsDir := filepath.Join(util.DataDir, "widgets") 32 entries, err := os.ReadDir(widgetsDir) 33 if err != nil { 34 logging.LogErrorf("read dir [%s] failed: %s", widgetsDir, err) 35 return 36 } 37 38 k := strings.ToLower(keyword) 39 var widgets []*bazaar.Widget 40 for _, entry := range entries { 41 if !util.IsDirRegularOrSymlink(entry) { 42 continue 43 } 44 if strings.HasPrefix(entry.Name(), ".") { 45 continue 46 } 47 48 widget, _ := bazaar.WidgetJSON(entry.Name()) 49 if nil == widget { 50 continue 51 } 52 53 widgets = append(widgets, widget) 54 } 55 56 widgets = filterWidgets(widgets, k) 57 for _, widget := range widgets { 58 b := &Block{ 59 Name: bazaar.GetPreferredName(widget.Package), 60 Content: widget.Name, 61 } 62 ret = append(ret, b) 63 } 64 65 return 66}