1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-12-02 21:27:48 +01:00
gojekyll/site/plugins.go

41 lines
990 B
Go
Raw Normal View History

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 {
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.
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
}
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
}