Add injected css/javascript to plugins (#3195)

* Add injected css/javascript to plugins
* Manual documentation
This commit is contained in:
WithoutPants
2022-12-05 15:08:22 +11:00
committed by GitHub
parent 87cea80e7b
commit b5b9023b3e
7 changed files with 190 additions and 83 deletions

View File

@@ -56,6 +56,35 @@ type Config struct {
// The hooks configurations for hooks registered by this plugin.
Hooks []*HookConfig `yaml:"hooks"`
// Javascript files that will be injected into the stash UI.
UI UIConfig `yaml:"ui"`
}
type UIConfig struct {
// Javascript files that will be injected into the stash UI.
Javascript []string `yaml:"javascript"`
// CSS files that will be injected into the stash UI.
CSS []string `yaml:"css"`
}
func (c UIConfig) getCSSFiles(parent Config) []string {
ret := make([]string, len(c.CSS))
for i, v := range c.CSS {
ret[i] = filepath.Join(parent.getConfigPath(), v)
}
return ret
}
func (c UIConfig) getJavascriptFiles(parent Config) []string {
ret := make([]string, len(c.Javascript))
for i, v := range c.Javascript {
ret[i] = filepath.Join(parent.getConfigPath(), v)
}
return ret
}
func (c Config) getPluginTasks(includePlugin bool) []*PluginTask {
@@ -121,6 +150,10 @@ func (c Config) toPlugin() *Plugin {
Version: c.Version,
Tasks: c.getPluginTasks(false),
Hooks: c.getPluginHooks(false),
UI: PluginUI{
Javascript: c.UI.getJavascriptFiles(c),
CSS: c.UI.getCSSFiles(c),
},
}
}

View File

@@ -31,6 +31,15 @@ type Plugin struct {
Version *string `json:"version"`
Tasks []*PluginTask `json:"tasks"`
Hooks []*PluginHook `json:"hooks"`
UI PluginUI `json:"ui"`
}
type PluginUI struct {
// Javascript files that will be injected into the stash UI.
Javascript []string `json:"javascript"`
// CSS files that will be injected into the stash UI.
CSS []string `json:"css"`
}
type ServerConfig interface {