add option for #106

This commit is contained in:
Henrique Dias 2017-04-15 16:14:08 +01:00
parent 55f4b75529
commit 6ef2cf88e0
No known key found for this signature in database
GPG Key ID: 936F5EB68D786730
2 changed files with 15 additions and 1 deletions

View File

@ -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 // RunHugo is used to run the static website generator
func RunHugo(c *Config, force bool) { func RunHugo(c *Config, force bool) {
if c.CleanPublic {
os.RemoveAll(c.Root + "public") os.RemoveAll(c.Root + "public")
}
// Prevent running if watching is enabled // Prevent running if watching is enabled
if b, pos := variables.StringInSlice("--watch", c.Args); b && !force { if b, pos := variables.StringInSlice("--watch", c.Args); b && !force {

View File

@ -10,6 +10,7 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"reflect" "reflect"
"strconv"
"strings" "strings"
"github.com/hacdias/caddy-filemanager" "github.com/hacdias/caddy-filemanager"
@ -70,6 +71,7 @@ type Config struct {
Args []string // Hugo arguments Args []string // Hugo arguments
BaseURL string // BaseURL of admin interface BaseURL string // BaseURL of admin interface
WebDavURL string WebDavURL string
CleanPublic bool
BeforePublish config.CommandFunc BeforePublish config.CommandFunc
AfterPublish 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) 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": case "before_publish":
if cfg.BeforePublish, err = config.CommandRunner(c); err != nil { if cfg.BeforePublish, err = config.CommandRunner(c); err != nil {
return cfg, &filemanager.FileManager{}, err return cfg, &filemanager.FileManager{}, err