mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-20 09:22:29 +00:00
Clean up server & build site logic. Fixed #94
This commit is contained in:
parent
e6ace71fec
commit
0318f7c149
3 changed files with 34 additions and 21 deletions
|
@ -19,8 +19,8 @@ import (
|
||||||
"github.com/mostafah/fsync"
|
"github.com/mostafah/fsync"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/hugo/hugolib"
|
"github.com/spf13/hugo/hugolib"
|
||||||
|
"github.com/spf13/hugo/utils"
|
||||||
"github.com/spf13/nitro"
|
"github.com/spf13/nitro"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -36,7 +36,10 @@ var HugoCmd = &cobra.Command{
|
||||||
love by spf13 and friends in Go.
|
love by spf13 and friends in Go.
|
||||||
|
|
||||||
Complete documentation is available at http://hugo.spf13.com`,
|
Complete documentation is available at http://hugo.spf13.com`,
|
||||||
Run: build,
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
InitializeConfig()
|
||||||
|
build()
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var Hugo *cobra.Commander
|
var Hugo *cobra.Commander
|
||||||
|
@ -46,10 +49,7 @@ var Source, Destination, BaseUrl, CfgFile string
|
||||||
func Execute() {
|
func Execute() {
|
||||||
AddCommands()
|
AddCommands()
|
||||||
Hugo := HugoCmd.ToCommander()
|
Hugo := HugoCmd.ToCommander()
|
||||||
err := Hugo.Execute()
|
utils.CheckErrExit(Hugo.Execute())
|
||||||
if err != nil {
|
|
||||||
os.Exit(-1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddCommands() {
|
func AddCommands() {
|
||||||
|
@ -84,25 +84,16 @@ func InitializeConfig() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func build(cmd *cobra.Command, args []string) {
|
func build() {
|
||||||
InitializeConfig()
|
utils.CheckErr(copyStatic(), fmt.Sprintf("Error copying static files to %s", Config.GetAbsPath(Config.PublishDir)))
|
||||||
|
|
||||||
err := copyStatic()
|
_, e := buildSite()
|
||||||
if err != nil {
|
utils.CheckErrExit(e)
|
||||||
log.Fatalf("Error copying static files to %s: %v", Config.GetAbsPath(Config.PublishDir), err)
|
|
||||||
}
|
|
||||||
if _, err := buildSite(); err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
os.Exit(-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if BuildWatch {
|
if BuildWatch {
|
||||||
fmt.Println("Watching for changes in", Config.GetAbsPath(Config.ContentDir))
|
fmt.Println("Watching for changes in", Config.GetAbsPath(Config.ContentDir))
|
||||||
fmt.Println("Press ctrl+c to stop")
|
fmt.Println("Press ctrl+c to stop")
|
||||||
err := NewWatcher(0)
|
utils.CheckErr(NewWatcher(0))
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ func server(cmd *cobra.Command, args []string) {
|
||||||
Config.BaseUrl = "http://localhost:" + strconv.Itoa(serverPort)
|
Config.BaseUrl = "http://localhost:" + strconv.Itoa(serverPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
build(cmd, args)
|
build()
|
||||||
|
|
||||||
// Watch runs its own server as part of the routine
|
// Watch runs its own server as part of the routine
|
||||||
if serverWatch {
|
if serverWatch {
|
||||||
|
|
22
utils/utils.go
Normal file
22
utils/utils.go
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CheckErr(err error, s ...string) {
|
||||||
|
if err != nil {
|
||||||
|
for _, message := range s {
|
||||||
|
log.Fatalf(message)
|
||||||
|
}
|
||||||
|
log.Fatalf("Fatal Error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CheckErrExit(err error, s ...string) {
|
||||||
|
if err != nil {
|
||||||
|
CheckErr(err, s...)
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue