mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-04 05:11:03 +08:00
🎨 Improve /widget search https://github.com/siyuan-note/siyuan/issues/10917
This commit is contained in:
parent
62db617f91
commit
1a487c0251
@ -76,7 +76,7 @@ func Icons() (icons []*Icon) {
|
|||||||
icon.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
|
icon.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
|
||||||
icon.Funding = repo.Package.Funding
|
icon.Funding = repo.Package.Funding
|
||||||
icon.PreferredFunding = getPreferredFunding(icon.Funding)
|
icon.PreferredFunding = getPreferredFunding(icon.Funding)
|
||||||
icon.PreferredName = getPreferredName(icon.Package)
|
icon.PreferredName = GetPreferredName(icon.Package)
|
||||||
icon.PreferredDesc = getPreferredDesc(icon.Description)
|
icon.PreferredDesc = getPreferredDesc(icon.Description)
|
||||||
icon.Updated = repo.Updated
|
icon.Updated = repo.Updated
|
||||||
icon.Stars = repo.Stars
|
icon.Stars = repo.Stars
|
||||||
@ -140,7 +140,7 @@ func InstalledIcons() (ret []*Icon) {
|
|||||||
icon.PreviewURLThumb = "/appearance/icons/" + dirName + "/preview.png"
|
icon.PreviewURLThumb = "/appearance/icons/" + dirName + "/preview.png"
|
||||||
icon.IconURL = "/appearance/icons/" + dirName + "/icon.png"
|
icon.IconURL = "/appearance/icons/" + dirName + "/icon.png"
|
||||||
icon.PreferredFunding = getPreferredFunding(icon.Funding)
|
icon.PreferredFunding = getPreferredFunding(icon.Funding)
|
||||||
icon.PreferredName = getPreferredName(icon.Package)
|
icon.PreferredName = GetPreferredName(icon.Package)
|
||||||
icon.PreferredDesc = getPreferredDesc(icon.Description)
|
icon.PreferredDesc = getPreferredDesc(icon.Description)
|
||||||
info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
|
info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
|
||||||
if nil != statErr {
|
if nil != statErr {
|
||||||
|
@ -161,7 +161,7 @@ func getPreferredReadme(readme *Readme) string {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPreferredName(pkg *Package) string {
|
func GetPreferredName(pkg *Package) string {
|
||||||
if nil == pkg.DisplayName {
|
if nil == pkg.DisplayName {
|
||||||
return pkg.Name
|
return pkg.Name
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ func Plugins(frontend string) (plugins []*Plugin) {
|
|||||||
plugin.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
|
plugin.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
|
||||||
plugin.Funding = repo.Package.Funding
|
plugin.Funding = repo.Package.Funding
|
||||||
plugin.PreferredFunding = getPreferredFunding(plugin.Funding)
|
plugin.PreferredFunding = getPreferredFunding(plugin.Funding)
|
||||||
plugin.PreferredName = getPreferredName(plugin.Package)
|
plugin.PreferredName = GetPreferredName(plugin.Package)
|
||||||
plugin.PreferredDesc = getPreferredDesc(plugin.Description)
|
plugin.PreferredDesc = getPreferredDesc(plugin.Description)
|
||||||
plugin.Updated = repo.Updated
|
plugin.Updated = repo.Updated
|
||||||
plugin.Stars = repo.Stars
|
plugin.Stars = repo.Stars
|
||||||
@ -136,7 +136,7 @@ func ParseInstalledPlugin(name, frontend string) (found bool, displayName string
|
|||||||
}
|
}
|
||||||
|
|
||||||
found = true
|
found = true
|
||||||
displayName = getPreferredName(plugin.Package)
|
displayName = GetPreferredName(plugin.Package)
|
||||||
incompatible = isIncompatiblePlugin(plugin, frontend)
|
incompatible = isIncompatiblePlugin(plugin, frontend)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -179,7 +179,7 @@ func InstalledPlugins(frontend string, checkUpdate bool) (ret []*Plugin) {
|
|||||||
plugin.PreviewURLThumb = "/plugins/" + dirName + "/preview.png"
|
plugin.PreviewURLThumb = "/plugins/" + dirName + "/preview.png"
|
||||||
plugin.IconURL = "/plugins/" + dirName + "/icon.png"
|
plugin.IconURL = "/plugins/" + dirName + "/icon.png"
|
||||||
plugin.PreferredFunding = getPreferredFunding(plugin.Funding)
|
plugin.PreferredFunding = getPreferredFunding(plugin.Funding)
|
||||||
plugin.PreferredName = getPreferredName(plugin.Package)
|
plugin.PreferredName = GetPreferredName(plugin.Package)
|
||||||
plugin.PreferredDesc = getPreferredDesc(plugin.Description)
|
plugin.PreferredDesc = getPreferredDesc(plugin.Description)
|
||||||
info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
|
info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
|
||||||
if nil != statErr {
|
if nil != statErr {
|
||||||
|
@ -78,7 +78,7 @@ func Templates() (templates []*Template) {
|
|||||||
template.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
|
template.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
|
||||||
template.Funding = repo.Package.Funding
|
template.Funding = repo.Package.Funding
|
||||||
template.PreferredFunding = getPreferredFunding(template.Funding)
|
template.PreferredFunding = getPreferredFunding(template.Funding)
|
||||||
template.PreferredName = getPreferredName(template.Package)
|
template.PreferredName = GetPreferredName(template.Package)
|
||||||
template.PreferredDesc = getPreferredDesc(template.Description)
|
template.PreferredDesc = getPreferredDesc(template.Description)
|
||||||
template.Updated = repo.Updated
|
template.Updated = repo.Updated
|
||||||
template.Stars = repo.Stars
|
template.Stars = repo.Stars
|
||||||
@ -142,7 +142,7 @@ func InstalledTemplates() (ret []*Template) {
|
|||||||
template.PreviewURLThumb = "/templates/" + dirName + "/preview.png"
|
template.PreviewURLThumb = "/templates/" + dirName + "/preview.png"
|
||||||
template.IconURL = "/templates/" + dirName + "/icon.png"
|
template.IconURL = "/templates/" + dirName + "/icon.png"
|
||||||
template.PreferredFunding = getPreferredFunding(template.Funding)
|
template.PreferredFunding = getPreferredFunding(template.Funding)
|
||||||
template.PreferredName = getPreferredName(template.Package)
|
template.PreferredName = GetPreferredName(template.Package)
|
||||||
template.PreferredDesc = getPreferredDesc(template.Description)
|
template.PreferredDesc = getPreferredDesc(template.Description)
|
||||||
info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
|
info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
|
||||||
if nil != statErr {
|
if nil != statErr {
|
||||||
|
@ -78,7 +78,7 @@ func Themes() (ret []*Theme) {
|
|||||||
theme.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
|
theme.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
|
||||||
theme.Funding = repo.Package.Funding
|
theme.Funding = repo.Package.Funding
|
||||||
theme.PreferredFunding = getPreferredFunding(theme.Funding)
|
theme.PreferredFunding = getPreferredFunding(theme.Funding)
|
||||||
theme.PreferredName = getPreferredName(theme.Package)
|
theme.PreferredName = GetPreferredName(theme.Package)
|
||||||
theme.PreferredDesc = getPreferredDesc(theme.Description)
|
theme.PreferredDesc = getPreferredDesc(theme.Description)
|
||||||
theme.Updated = repo.Updated
|
theme.Updated = repo.Updated
|
||||||
theme.Stars = repo.Stars
|
theme.Stars = repo.Stars
|
||||||
@ -142,7 +142,7 @@ func InstalledThemes() (ret []*Theme) {
|
|||||||
theme.PreviewURLThumb = "/appearance/themes/" + dirName + "/preview.png"
|
theme.PreviewURLThumb = "/appearance/themes/" + dirName + "/preview.png"
|
||||||
theme.IconURL = "/appearance/themes/" + dirName + "/icon.png"
|
theme.IconURL = "/appearance/themes/" + dirName + "/icon.png"
|
||||||
theme.PreferredFunding = getPreferredFunding(theme.Funding)
|
theme.PreferredFunding = getPreferredFunding(theme.Funding)
|
||||||
theme.PreferredName = getPreferredName(theme.Package)
|
theme.PreferredName = GetPreferredName(theme.Package)
|
||||||
theme.PreferredDesc = getPreferredDesc(theme.Description)
|
theme.PreferredDesc = getPreferredDesc(theme.Description)
|
||||||
info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
|
info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
|
||||||
if nil != statErr {
|
if nil != statErr {
|
||||||
|
@ -78,7 +78,7 @@ func Widgets() (widgets []*Widget) {
|
|||||||
widget.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
|
widget.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
|
||||||
widget.Funding = repo.Package.Funding
|
widget.Funding = repo.Package.Funding
|
||||||
widget.PreferredFunding = getPreferredFunding(widget.Funding)
|
widget.PreferredFunding = getPreferredFunding(widget.Funding)
|
||||||
widget.PreferredName = getPreferredName(widget.Package)
|
widget.PreferredName = GetPreferredName(widget.Package)
|
||||||
widget.PreferredDesc = getPreferredDesc(widget.Description)
|
widget.PreferredDesc = getPreferredDesc(widget.Description)
|
||||||
widget.Updated = repo.Updated
|
widget.Updated = repo.Updated
|
||||||
widget.Stars = repo.Stars
|
widget.Stars = repo.Stars
|
||||||
@ -140,7 +140,7 @@ func InstalledWidgets() (ret []*Widget) {
|
|||||||
widget.PreviewURLThumb = "/widgets/" + dirName + "/preview.png"
|
widget.PreviewURLThumb = "/widgets/" + dirName + "/preview.png"
|
||||||
widget.IconURL = "/widgets/" + dirName + "/icon.png"
|
widget.IconURL = "/widgets/" + dirName + "/icon.png"
|
||||||
widget.PreferredFunding = getPreferredFunding(widget.Funding)
|
widget.PreferredFunding = getPreferredFunding(widget.Funding)
|
||||||
widget.PreferredName = getPreferredName(widget.Package)
|
widget.PreferredName = GetPreferredName(widget.Package)
|
||||||
widget.PreferredDesc = getPreferredDesc(widget.Description)
|
widget.PreferredDesc = getPreferredDesc(widget.Description)
|
||||||
info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
|
info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
|
||||||
if nil != statErr {
|
if nil != statErr {
|
||||||
|
@ -22,54 +22,45 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
"github.com/siyuan-note/siyuan/kernel/search"
|
"github.com/siyuan-note/siyuan/kernel/bazaar"
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SearchWidget(keyword string) (ret []*Block) {
|
func SearchWidget(keyword string) (ret []*Block) {
|
||||||
ret = []*Block{}
|
ret = []*Block{}
|
||||||
widgets := filepath.Join(util.DataDir, "widgets")
|
widgetsDir := filepath.Join(util.DataDir, "widgets")
|
||||||
entries, err := os.ReadDir(widgets)
|
entries, err := os.ReadDir(widgetsDir)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logging.LogErrorf("read dir [%s] failed: %s", widgets, err)
|
logging.LogErrorf("read dir [%s] failed: %s", widgetsDir, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
k := strings.ToLower(keyword)
|
k := strings.ToLower(keyword)
|
||||||
|
var widgets []*bazaar.Widget
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
if !util.IsDirRegularOrSymlink(entry) {
|
if !util.IsDirRegularOrSymlink(entry) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if strings.HasPrefix(entry.Name(), ".") {
|
||||||
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
name := strings.ToLower(entry.Name())
|
widget, _ := bazaar.WidgetJSON(entry.Name())
|
||||||
if strings.HasPrefix(name, ".") {
|
if nil == widget {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(name, k) {
|
widgets = append(widgets, widget)
|
||||||
name = entry.Name()
|
}
|
||||||
if "" != keyword {
|
|
||||||
_, name = search.MarkText(entry.Name(), keyword, 32, Conf.Search.CaseSensitive)
|
widgets = filterWidgets(widgets, k)
|
||||||
|
for _, widget := range widgets {
|
||||||
|
b := &Block{
|
||||||
|
Name: bazaar.GetPreferredName(widget.Package),
|
||||||
|
Content: widget.Name,
|
||||||
}
|
}
|
||||||
b := &Block{Content: name}
|
|
||||||
ret = append(ret, b)
|
ret = append(ret, b)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user