diff --git a/hugo.go b/hugo.go index f5d124c6..191c81c3 100644 --- a/hugo.go +++ b/hugo.go @@ -133,7 +133,9 @@ func (h Hugo) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { // RunHugo is used to run the static website generator func RunHugo(c *Config, force bool) { - os.RemoveAll(c.Root + "public") + if c.CleanPublic { + os.RemoveAll(c.Root + "public") + } // Prevent running if watching is enabled if b, pos := variables.StringInSlice("--watch", c.Args); b && !force { diff --git a/setup.go b/setup.go index 8e497a82..a51a5e27 100644 --- a/setup.go +++ b/setup.go @@ -10,6 +10,7 @@ import ( "os/exec" "path/filepath" "reflect" + "strconv" "strings" "github.com/hacdias/caddy-filemanager" @@ -70,6 +71,7 @@ type Config struct { Args []string // Hugo arguments BaseURL string // BaseURL of admin interface WebDavURL string + CleanPublic bool BeforePublish config.CommandFunc AfterPublish config.CommandFunc } @@ -127,6 +129,16 @@ func parse(c *caddy.Controller, root string) (*Config, *filemanager.FileManager, } cfg.Args = append(cfg.Args, "--"+flag+"="+value) + case "clean_public": + if !c.NextArg() { + return cfg, &filemanager.FileManager{}, c.ArgErr() + } + + cfg.CleanPublic, err = strconv.ParseBool(c.Val()) + + if err != nil { + return cfg, &filemanager.FileManager{}, c.ArgErr() + } case "before_publish": if cfg.BeforePublish, err = config.CommandRunner(c); err != nil { return cfg, &filemanager.FileManager{}, err