call hugo as external command

This commit is contained in:
Henrique Dias
2016-02-20 11:31:59 +00:00
parent a9ba42c3d0
commit 9e135967cb
3 changed files with 26 additions and 21 deletions

View File

@@ -6,6 +6,7 @@ import (
"log"
"net/http"
"os"
"os/exec"
"reflect"
"strings"
"text/template"
@@ -13,8 +14,6 @@ import (
"github.com/hacdias/caddy-hugo/assets"
"github.com/hacdias/caddy-hugo/config"
"github.com/spf13/hugo/commands"
"github.com/spf13/viper"
)
// CanBeEdited checks if the extension of a file is supported by the editor
@@ -168,14 +167,20 @@ func ParseComponents(r *http.Request) []string {
func Run(c *config.Config) {
os.RemoveAll(c.Path + "public")
commands.MainSite = nil
viper.Reset()
commands.HugoCmd.ParseFlags(c.Args)
if err := commands.HugoCmd.RunE(nil, nil); err != nil {
if err := RunCommand("hugo", c.Args, c.Path); err != nil {
log.Panic(err)
}
}
// RunCommand executes an external command
func RunCommand(command string, args []string, path string) error {
cmd := exec.Command(command, args...)
cmd.Dir = path
cmd.Stdout = os.Stderr
cmd.Stderr = os.Stderr
return cmd.Run()
}
var splitCapitalizeExceptions = map[string]string{
"youtube": "YouTube",
"github": "GitHub",