2017-09-01 15:10:07 +02:00
|
|
|
package site
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/osteele/gojekyll/plugins"
|
|
|
|
"github.com/osteele/gojekyll/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Site) installPlugins() error {
|
2017-09-01 15:40:27 +02:00
|
|
|
s.plugins = s.cfg.Plugins
|
2017-09-01 15:27:03 +02:00
|
|
|
installed := utils.StringSet{}
|
|
|
|
// Install plugins and call their ModifyPluginList methods.
|
|
|
|
// Repeat until no plugins have been added.
|
2017-09-01 15:40:27 +02:00
|
|
|
for len(s.plugins) > len(installed) {
|
|
|
|
// Collect plugins into a list instead of map, in order to preserve order
|
|
|
|
pending := utils.StringList(s.plugins).Reject(installed.Contains)
|
2017-09-01 15:10:07 +02:00
|
|
|
if err := plugins.Install(pending, s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-09-01 15:40:27 +02:00
|
|
|
for _, name := range pending {
|
|
|
|
p, ok := plugins.Lookup(name)
|
|
|
|
if ok {
|
|
|
|
s.plugins = p.ModifyPluginList(s.plugins)
|
2017-09-01 15:10:07 +02:00
|
|
|
}
|
|
|
|
}
|
2017-09-01 15:27:03 +02:00
|
|
|
installed.AddStrings(pending)
|
2017-09-01 15:10:07 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Site) runHooks(h func(plugins.Plugin) error) error {
|
|
|
|
for _, name := range s.plugins {
|
|
|
|
p, ok := plugins.Lookup(name)
|
|
|
|
if ok {
|
|
|
|
if err := h(p); err != nil {
|
|
|
|
return utils.WrapError(err, "running plugin")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|