From af8dbc2180b5ae2fd2666de30dc68882e6c316d8 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sun, 18 Dec 2016 12:40:56 +0000 Subject: [PATCH] before publish and after publish commands --- hugo.go | 16 ++++++++++++++++ setup.go | 24 +++++++++++++++++------- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/hugo.go b/hugo.go index 69166b94..e99c712c 100644 --- a/hugo.go +++ b/hugo.go @@ -101,7 +101,23 @@ func (h Hugo) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { } if r.Header.Get("Regenerate") == "true" { + if err = h.Config.BeforePublish( + r, + &h.FileManager.Configs[0], + h.FileManager.Configs[0].User, + ); err != nil { + return http.StatusInternalServerError, err + } + RunHugo(h.Config, false) + + if err = h.Config.AfterPublish( + r, + &h.FileManager.Configs[0], + h.FileManager.Configs[0].User, + ); err != nil { + return http.StatusInternalServerError, err + } } if r.Header.Get("Schedule") != "" { diff --git a/setup.go b/setup.go index b03bc5ad..22e96cb1 100644 --- a/setup.go +++ b/setup.go @@ -62,13 +62,15 @@ func setup(c *caddy.Controller) error { // Config is a configuration for managing a particular hugo website. type Config struct { - Public string // Public content path - Root string // Hugo files path - Hugo string // Hugo executable location - Styles string // Admin styles path - Args []string // Hugo arguments - BaseURL string // BaseURL of admin interface - WebDavURL string + Public string // Public content path + Root string // Hugo files path + Hugo string // Hugo executable location + Styles string // Admin styles path + Args []string // Hugo arguments + BaseURL string // BaseURL of admin interface + WebDavURL string + BeforePublish config.CommandFunc + AfterPublish config.CommandFunc } // Parse parses the configuration set by the user so it can be @@ -127,6 +129,14 @@ func parse(c *caddy.Controller, root string) (*Config, *filemanager.FileManager, } cfg.Args = append(cfg.Args, "--"+values[0]+"="+value) + case "before_publish": + if cfg.BeforePublish, err = config.CommandRunner(c); err != nil { + return cfg, &filemanager.FileManager{}, err + } + case "after_publish": + if cfg.AfterPublish, err = config.CommandRunner(c); err != nil { + return cfg, &filemanager.FileManager{}, err + } default: line := "\n\t" + c.Val()