|
@@ -20,6 +20,7 @@ import (
|
|
"errors"
|
|
"errors"
|
|
"fmt"
|
|
"fmt"
|
|
"path/filepath"
|
|
"path/filepath"
|
|
|
|
+ "strings"
|
|
|
|
|
|
"github.com/88250/gulu"
|
|
"github.com/88250/gulu"
|
|
"github.com/siyuan-note/siyuan/kernel/util"
|
|
"github.com/siyuan-note/siyuan/kernel/util"
|
|
@@ -32,8 +33,9 @@ func GetPackageREADME(repoURL, repoHash, packageType string) (ret string) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-func BazaarPlugins(frontend string) (plugins []*bazaar.Plugin) {
|
|
|
|
|
|
+func BazaarPlugins(frontend, keyword string) (plugins []*bazaar.Plugin) {
|
|
plugins = bazaar.Plugins(frontend)
|
|
plugins = bazaar.Plugins(frontend)
|
|
|
|
+ plugins = filterPlugins(plugins, keyword)
|
|
for _, plugin := range plugins {
|
|
for _, plugin := range plugins {
|
|
plugin.Installed = util.IsPathRegularDirOrSymlinkDir(filepath.Join(util.DataDir, "plugins", plugin.Name))
|
|
plugin.Installed = util.IsPathRegularDirOrSymlinkDir(filepath.Join(util.DataDir, "plugins", plugin.Name))
|
|
if plugin.Installed {
|
|
if plugin.Installed {
|
|
@@ -49,6 +51,29 @@ func BazaarPlugins(frontend string) (plugins []*bazaar.Plugin) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func filterPlugins(packages []*bazaar.Plugin, keyword string) (ret []*bazaar.Plugin) {
|
|
|
|
+ ret = []*bazaar.Plugin{}
|
|
|
|
+ keyword = strings.TrimSpace(keyword)
|
|
|
|
+ if "" == keyword {
|
|
|
|
+ return packages
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for _, pkg := range packages {
|
|
|
|
+ if strings.Contains(pkg.DisplayName.Default, keyword) ||
|
|
|
|
+ strings.Contains(pkg.DisplayName.ZhCN, keyword) ||
|
|
|
|
+ strings.Contains(pkg.DisplayName.ZhCHT, keyword) ||
|
|
|
|
+ strings.Contains(pkg.DisplayName.EnUS, keyword) ||
|
|
|
|
+ strings.Contains(pkg.Description.Default, keyword) ||
|
|
|
|
+ strings.Contains(pkg.Description.ZhCN, keyword) ||
|
|
|
|
+ strings.Contains(pkg.Description.ZhCHT, keyword) ||
|
|
|
|
+ strings.Contains(pkg.Description.EnUS, keyword) {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ ret = append(ret, pkg)
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
func InstalledPlugins(frontend string) (plugins []*bazaar.Plugin) {
|
|
func InstalledPlugins(frontend string) (plugins []*bazaar.Plugin) {
|
|
plugins = bazaar.InstalledPlugins(frontend, true)
|
|
plugins = bazaar.InstalledPlugins(frontend, true)
|
|
|
|
|
|
@@ -93,8 +118,9 @@ func UninstallBazaarPlugin(pluginName, frontend string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func BazaarWidgets() (widgets []*bazaar.Widget) {
|
|
|
|
|
|
+func BazaarWidgets(keyword string) (widgets []*bazaar.Widget) {
|
|
widgets = bazaar.Widgets()
|
|
widgets = bazaar.Widgets()
|
|
|
|
+ widgets = filterWidgets(widgets, keyword)
|
|
for _, widget := range widgets {
|
|
for _, widget := range widgets {
|
|
widget.Installed = util.IsPathRegularDirOrSymlinkDir(filepath.Join(util.DataDir, "widgets", widget.Name))
|
|
widget.Installed = util.IsPathRegularDirOrSymlinkDir(filepath.Join(util.DataDir, "widgets", widget.Name))
|
|
if widget.Installed {
|
|
if widget.Installed {
|
|
@@ -110,6 +136,29 @@ func BazaarWidgets() (widgets []*bazaar.Widget) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func filterWidgets(packages []*bazaar.Widget, keyword string) (ret []*bazaar.Widget) {
|
|
|
|
+ ret = []*bazaar.Widget{}
|
|
|
|
+ keyword = strings.TrimSpace(keyword)
|
|
|
|
+ if "" == keyword {
|
|
|
|
+ return packages
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for _, pkg := range packages {
|
|
|
|
+ if strings.Contains(pkg.DisplayName.Default, keyword) ||
|
|
|
|
+ strings.Contains(pkg.DisplayName.ZhCN, keyword) ||
|
|
|
|
+ strings.Contains(pkg.DisplayName.ZhCHT, keyword) ||
|
|
|
|
+ strings.Contains(pkg.DisplayName.EnUS, keyword) ||
|
|
|
|
+ strings.Contains(pkg.Description.Default, keyword) ||
|
|
|
|
+ strings.Contains(pkg.Description.ZhCN, keyword) ||
|
|
|
|
+ strings.Contains(pkg.Description.ZhCHT, keyword) ||
|
|
|
|
+ strings.Contains(pkg.Description.EnUS, keyword) {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ ret = append(ret, pkg)
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
func InstalledWidgets() (widgets []*bazaar.Widget) {
|
|
func InstalledWidgets() (widgets []*bazaar.Widget) {
|
|
widgets = bazaar.InstalledWidgets()
|
|
widgets = bazaar.InstalledWidgets()
|
|
return
|
|
return
|
|
@@ -133,8 +182,9 @@ func UninstallBazaarWidget(widgetName string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func BazaarIcons() (icons []*bazaar.Icon) {
|
|
|
|
|
|
+func BazaarIcons(keyword string) (icons []*bazaar.Icon) {
|
|
icons = bazaar.Icons()
|
|
icons = bazaar.Icons()
|
|
|
|
+ icons = filterIcons(icons, keyword)
|
|
for _, installed := range Conf.Appearance.Icons {
|
|
for _, installed := range Conf.Appearance.Icons {
|
|
for _, icon := range icons {
|
|
for _, icon := range icons {
|
|
if installed == icon.Name {
|
|
if installed == icon.Name {
|
|
@@ -151,6 +201,29 @@ func BazaarIcons() (icons []*bazaar.Icon) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func filterIcons(packages []*bazaar.Icon, keyword string) (ret []*bazaar.Icon) {
|
|
|
|
+ ret = []*bazaar.Icon{}
|
|
|
|
+ keyword = strings.TrimSpace(keyword)
|
|
|
|
+ if "" == keyword {
|
|
|
|
+ return packages
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for _, pkg := range packages {
|
|
|
|
+ if strings.Contains(pkg.DisplayName.Default, keyword) ||
|
|
|
|
+ strings.Contains(pkg.DisplayName.ZhCN, keyword) ||
|
|
|
|
+ strings.Contains(pkg.DisplayName.ZhCHT, keyword) ||
|
|
|
|
+ strings.Contains(pkg.DisplayName.EnUS, keyword) ||
|
|
|
|
+ strings.Contains(pkg.Description.Default, keyword) ||
|
|
|
|
+ strings.Contains(pkg.Description.ZhCN, keyword) ||
|
|
|
|
+ strings.Contains(pkg.Description.ZhCHT, keyword) ||
|
|
|
|
+ strings.Contains(pkg.Description.EnUS, keyword) {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ ret = append(ret, pkg)
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
func InstalledIcons() (icons []*bazaar.Icon) {
|
|
func InstalledIcons() (icons []*bazaar.Icon) {
|
|
icons = bazaar.InstalledIcons()
|
|
icons = bazaar.InstalledIcons()
|
|
for _, icon := range icons {
|
|
for _, icon := range icons {
|
|
@@ -182,8 +255,9 @@ func UninstallBazaarIcon(iconName string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func BazaarThemes() (ret []*bazaar.Theme) {
|
|
|
|
|
|
+func BazaarThemes(keyword string) (ret []*bazaar.Theme) {
|
|
ret = bazaar.Themes()
|
|
ret = bazaar.Themes()
|
|
|
|
+ ret = filterThemes(ret, keyword)
|
|
installs := Conf.Appearance.DarkThemes
|
|
installs := Conf.Appearance.DarkThemes
|
|
installs = append(installs, Conf.Appearance.LightThemes...)
|
|
installs = append(installs, Conf.Appearance.LightThemes...)
|
|
for _, installed := range installs {
|
|
for _, installed := range installs {
|
|
@@ -200,6 +274,29 @@ func BazaarThemes() (ret []*bazaar.Theme) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func filterThemes(packages []*bazaar.Theme, keyword string) (ret []*bazaar.Theme) {
|
|
|
|
+ ret = []*bazaar.Theme{}
|
|
|
|
+ keyword = strings.TrimSpace(keyword)
|
|
|
|
+ if "" == keyword {
|
|
|
|
+ return packages
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for _, pkg := range packages {
|
|
|
|
+ if strings.Contains(pkg.DisplayName.Default, keyword) ||
|
|
|
|
+ strings.Contains(pkg.DisplayName.ZhCN, keyword) ||
|
|
|
|
+ strings.Contains(pkg.DisplayName.ZhCHT, keyword) ||
|
|
|
|
+ strings.Contains(pkg.DisplayName.EnUS, keyword) ||
|
|
|
|
+ strings.Contains(pkg.Description.Default, keyword) ||
|
|
|
|
+ strings.Contains(pkg.Description.ZhCN, keyword) ||
|
|
|
|
+ strings.Contains(pkg.Description.ZhCHT, keyword) ||
|
|
|
|
+ strings.Contains(pkg.Description.EnUS, keyword) {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ ret = append(ret, pkg)
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
func InstalledThemes() (ret []*bazaar.Theme) {
|
|
func InstalledThemes() (ret []*bazaar.Theme) {
|
|
ret = bazaar.InstalledThemes()
|
|
ret = bazaar.InstalledThemes()
|
|
for _, theme := range ret {
|
|
for _, theme := range ret {
|
|
@@ -246,8 +343,9 @@ func UninstallBazaarTheme(themeName string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func BazaarTemplates() (templates []*bazaar.Template) {
|
|
|
|
|
|
+func BazaarTemplates(keyword string) (templates []*bazaar.Template) {
|
|
templates = bazaar.Templates()
|
|
templates = bazaar.Templates()
|
|
|
|
+ templates = filterTemplates(templates, keyword)
|
|
for _, template := range templates {
|
|
for _, template := range templates {
|
|
template.Installed = util.IsPathRegularDirOrSymlinkDir(filepath.Join(util.DataDir, "templates", template.Name))
|
|
template.Installed = util.IsPathRegularDirOrSymlinkDir(filepath.Join(util.DataDir, "templates", template.Name))
|
|
if template.Installed {
|
|
if template.Installed {
|
|
@@ -261,6 +359,29 @@ func BazaarTemplates() (templates []*bazaar.Template) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func filterTemplates(packages []*bazaar.Template, keyword string) (ret []*bazaar.Template) {
|
|
|
|
+ ret = []*bazaar.Template{}
|
|
|
|
+ keyword = strings.TrimSpace(keyword)
|
|
|
|
+ if "" == keyword {
|
|
|
|
+ return packages
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for _, pkg := range packages {
|
|
|
|
+ if strings.Contains(pkg.DisplayName.Default, keyword) ||
|
|
|
|
+ strings.Contains(pkg.DisplayName.ZhCN, keyword) ||
|
|
|
|
+ strings.Contains(pkg.DisplayName.ZhCHT, keyword) ||
|
|
|
|
+ strings.Contains(pkg.DisplayName.EnUS, keyword) ||
|
|
|
|
+ strings.Contains(pkg.Description.Default, keyword) ||
|
|
|
|
+ strings.Contains(pkg.Description.ZhCN, keyword) ||
|
|
|
|
+ strings.Contains(pkg.Description.ZhCHT, keyword) ||
|
|
|
|
+ strings.Contains(pkg.Description.EnUS, keyword) {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ ret = append(ret, pkg)
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
func InstalledTemplates() (templates []*bazaar.Template) {
|
|
func InstalledTemplates() (templates []*bazaar.Template) {
|
|
templates = bazaar.InstalledTemplates()
|
|
templates = bazaar.InstalledTemplates()
|
|
return
|
|
return
|