🎨 Init plugin system https://github.com/siyuan-note/siyuan/issues/8041
This commit is contained in:
parent
e1edc4684e
commit
b7ae8295a5
6 changed files with 66 additions and 8 deletions
|
@ -71,6 +71,8 @@ func Icons() (icons []*Icon) {
|
|||
icon.PreviewURL = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageslim"
|
||||
icon.PreviewURLThumb = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageView2/2/w/436/h/232"
|
||||
icon.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
|
||||
icon.Funding = parseFunding(repo["package"].(map[string]interface{}))
|
||||
icon.PreferredFunding = getPreferredFunding(icon.Funding)
|
||||
icon.Updated = repo["updated"].(string)
|
||||
icon.Stars = int(repo["stars"].(float64))
|
||||
icon.OpenIssues = int(repo["openIssues"].(float64))
|
||||
|
@ -134,6 +136,7 @@ func InstalledIcons() (ret []*Icon) {
|
|||
icon.PreviewURLThumb = "/appearance/icons/" + dirName + "/preview.png"
|
||||
icon.IconURL = "/appearance/icons/" + dirName + "/icon.png"
|
||||
icon.Funding = parseFunding(iconConf)
|
||||
icon.PreferredFunding = getPreferredFunding(icon.Funding)
|
||||
info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
|
||||
if nil != statErr {
|
||||
logging.LogWarnf("stat install theme README.md failed: %s", statErr)
|
||||
|
|
|
@ -38,6 +38,18 @@ import (
|
|||
"golang.org/x/text/transform"
|
||||
)
|
||||
|
||||
type Description struct {
|
||||
Default string `json:"default"`
|
||||
ZhCN string `json:"zh_CN"`
|
||||
EnUS string `json:"en_US"`
|
||||
}
|
||||
|
||||
type Readme struct {
|
||||
Default string `json:"default"`
|
||||
ZhCN string `json:"zh_CN"`
|
||||
EnUS string `json:"en_US"`
|
||||
}
|
||||
|
||||
type Funding struct {
|
||||
OpenCollective string `json:"openCollective"`
|
||||
Patreon string `json:"patreon"`
|
||||
|
@ -46,10 +58,15 @@ type Funding struct {
|
|||
}
|
||||
|
||||
type Package struct {
|
||||
Author string `json:"author"`
|
||||
URL string `json:"url"`
|
||||
Version string `json:"version"`
|
||||
Funding *Funding `json:"funding"`
|
||||
Author string `json:"author"`
|
||||
URL string `json:"url"`
|
||||
Version string `json:"version"`
|
||||
Description *Description `json:"description"`
|
||||
Readme *Readme `json:"readme"`
|
||||
Funding *Funding `json:"funding"`
|
||||
|
||||
PreferredFunding string `json:"preferredFunding"`
|
||||
PreferredDesc string `json:"preferredDesc"`
|
||||
|
||||
Name string `json:"name"`
|
||||
RepoURL string `json:"repoURL"`
|
||||
|
@ -75,16 +92,42 @@ type Package struct {
|
|||
Downloads int `json:"downloads"`
|
||||
}
|
||||
|
||||
func parseFunding(conf map[string]interface{}) (ret *Funding) {
|
||||
func parseFunding(pkg map[string]interface{}) (ret *Funding) {
|
||||
if nil == pkg["funding"] {
|
||||
return
|
||||
}
|
||||
|
||||
ret = &Funding{}
|
||||
funding := conf["funding"].(map[string]interface{})
|
||||
funding := pkg["funding"].(map[string]interface{})
|
||||
ret.OpenCollective = funding["openCollective"].(string)
|
||||
ret.Patreon = funding["patreon"].(string)
|
||||
ret.GitHub = funding["github"].(string)
|
||||
ret.Custom = funding["custom"].([]string)
|
||||
|
||||
customURLs := funding["custom"].([]interface{})
|
||||
var custom []string
|
||||
for _, customURL := range customURLs {
|
||||
custom = append(custom, customURL.(string))
|
||||
}
|
||||
ret.Custom = custom
|
||||
return
|
||||
}
|
||||
|
||||
func getPreferredFunding(funding *Funding) string {
|
||||
if "" != funding.OpenCollective {
|
||||
return funding.OpenCollective
|
||||
}
|
||||
if "" != funding.Patreon {
|
||||
return funding.Patreon
|
||||
}
|
||||
if "" != funding.GitHub {
|
||||
return funding.GitHub
|
||||
}
|
||||
if 0 < len(funding.Custom) {
|
||||
return funding.Custom[0]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func PluginJSON(pluginDirName string) (ret map[string]interface{}, err error) {
|
||||
p := filepath.Join(util.DataDir, "plugins", pluginDirName, "plugin.json")
|
||||
if !gulu.File.IsExist(p) {
|
||||
|
|
|
@ -54,7 +54,7 @@ func Plugins() (plugins []*Plugin) {
|
|||
repo := arg.(map[string]interface{})
|
||||
repoURL := repo["url"].(string)
|
||||
|
||||
plugin := &Plugin{}
|
||||
plugin := &Plugin{Package{Funding: &Funding{}, Description: &Description{}}}
|
||||
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/plugin.json"
|
||||
innerResp, innerErr := httpclient.NewBrowserRequest().SetSuccessResult(plugin).Get(innerU)
|
||||
if nil != innerErr {
|
||||
|
@ -73,6 +73,8 @@ func Plugins() (plugins []*Plugin) {
|
|||
plugin.PreviewURL = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageslim"
|
||||
plugin.PreviewURLThumb = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageView2/2/w/436/h/232"
|
||||
plugin.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
|
||||
plugin.Funding = parseFunding(repo["package"].(map[string]interface{}))
|
||||
plugin.PreferredFunding = getPreferredFunding(plugin.Funding)
|
||||
plugin.Updated = repo["updated"].(string)
|
||||
plugin.Stars = int(repo["stars"].(float64))
|
||||
plugin.OpenIssues = int(repo["openIssues"].(float64))
|
||||
|
@ -139,6 +141,7 @@ func InstalledPlugins() (ret []*Plugin) {
|
|||
plugin.PreviewURLThumb = "/plugins/" + dirName + "/preview.png"
|
||||
plugin.IconURL = "/plugins/" + dirName + "/icon.png"
|
||||
plugin.Funding = parseFunding(pluginConf)
|
||||
plugin.PreferredFunding = getPreferredFunding(plugin.Funding)
|
||||
info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
|
||||
if nil != statErr {
|
||||
logging.LogWarnf("stat install theme README.md failed: %s", statErr)
|
||||
|
|
|
@ -73,6 +73,8 @@ func Templates() (templates []*Template) {
|
|||
template.PreviewURL = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageslim"
|
||||
template.PreviewURLThumb = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageView2/2/w/436/h/232"
|
||||
template.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
|
||||
template.Funding = parseFunding(repo["package"].(map[string]interface{}))
|
||||
template.PreferredFunding = getPreferredFunding(template.Funding)
|
||||
template.Updated = repo["updated"].(string)
|
||||
template.Stars = int(repo["stars"].(float64))
|
||||
template.OpenIssues = int(repo["openIssues"].(float64))
|
||||
|
@ -141,6 +143,7 @@ func InstalledTemplates() (ret []*Template) {
|
|||
template.PreviewURLThumb = "/templates/" + dirName + "/preview.png"
|
||||
template.IconURL = "/templates/" + dirName + "/icon.png"
|
||||
template.Funding = parseFunding(templateConf)
|
||||
template.PreferredFunding = getPreferredFunding(template.Funding)
|
||||
info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
|
||||
if nil != statErr {
|
||||
logging.LogWarnf("stat install theme README.md failed: %s", statErr)
|
||||
|
|
|
@ -74,6 +74,8 @@ func Themes() (ret []*Theme) {
|
|||
theme.PreviewURL = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageslim"
|
||||
theme.PreviewURLThumb = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageView2/2/w/436/h/232"
|
||||
theme.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
|
||||
theme.Funding = parseFunding(repo["package"].(map[string]interface{}))
|
||||
theme.PreferredFunding = getPreferredFunding(theme.Funding)
|
||||
theme.Updated = repo["updated"].(string)
|
||||
theme.Stars = int(repo["stars"].(float64))
|
||||
theme.OpenIssues = int(repo["openIssues"].(float64))
|
||||
|
@ -145,6 +147,7 @@ func InstalledThemes() (ret []*Theme) {
|
|||
theme.PreviewURLThumb = "/appearance/themes/" + dirName + "/preview.png"
|
||||
theme.IconURL = "/appearance/themes/" + dirName + "/icon.png"
|
||||
theme.Funding = parseFunding(themeConf)
|
||||
theme.PreferredFunding = getPreferredFunding(theme.Funding)
|
||||
info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
|
||||
if nil != statErr {
|
||||
logging.LogWarnf("stat install theme README.md failed: %s", statErr)
|
||||
|
|
|
@ -73,6 +73,8 @@ func Widgets() (widgets []*Widget) {
|
|||
widget.PreviewURL = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageslim"
|
||||
widget.PreviewURLThumb = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageView2/2/w/436/h/232"
|
||||
widget.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
|
||||
widget.Funding = parseFunding(repo["package"].(map[string]interface{}))
|
||||
widget.PreferredFunding = getPreferredFunding(widget.Funding)
|
||||
widget.Updated = repo["updated"].(string)
|
||||
widget.Stars = int(repo["stars"].(float64))
|
||||
widget.OpenIssues = int(repo["openIssues"].(float64))
|
||||
|
@ -139,6 +141,7 @@ func InstalledWidgets() (ret []*Widget) {
|
|||
widget.PreviewURLThumb = "/widgets/" + dirName + "/preview.png"
|
||||
widget.IconURL = "/widgets/" + dirName + "/icon.png"
|
||||
widget.Funding = parseFunding(widgetConf)
|
||||
widget.PreferredFunding = getPreferredFunding(widget.Funding)
|
||||
info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
|
||||
if nil != statErr {
|
||||
logging.LogWarnf("stat install theme README.md failed: %s", statErr)
|
||||
|
|
Loading…
Add table
Reference in a new issue