2016-03-03 21:15:54 +00:00
|
|
|
package hugo
|
2016-02-20 22:31:46 +00:00
|
|
|
|
|
|
|
import (
|
2016-02-21 11:51:31 +00:00
|
|
|
"log"
|
2016-02-20 22:31:46 +00:00
|
|
|
"os"
|
2016-03-03 21:15:54 +00:00
|
|
|
|
2016-03-06 19:18:46 +00:00
|
|
|
"github.com/hacdias/caddy-hugo/config"
|
2016-03-06 20:37:49 +00:00
|
|
|
"github.com/hacdias/caddy-hugo/tools/commands"
|
2016-02-21 11:51:31 +00:00
|
|
|
)
|
2016-02-20 22:31:46 +00:00
|
|
|
|
2016-03-06 19:18:46 +00:00
|
|
|
// Run is used to run the static website generator
|
|
|
|
func Run(c *config.Config, force bool) {
|
|
|
|
os.RemoveAll(c.Path + "public")
|
|
|
|
|
|
|
|
// Prevent running if watching is enabled
|
|
|
|
if b, pos := stringInSlice("--watch", c.Args); b && !force {
|
|
|
|
if len(c.Args) > pos && c.Args[pos+1] != "false" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(c.Args) == pos+1 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-06 20:37:49 +00:00
|
|
|
if err := commands.Run(c.Hugo, c.Args, c.Path); err != nil {
|
2016-03-06 19:18:46 +00:00
|
|
|
log.Panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func stringInSlice(a string, list []string) (bool, int) {
|
|
|
|
for i, b := range list {
|
|
|
|
if b == a {
|
|
|
|
return true, i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false, 0
|
|
|
|
}
|