mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
Add support for dynamic reloading of config file when watching
This commit is contained in:
parent
488966dcb2
commit
bccf957e36
3 changed files with 21 additions and 6 deletions
|
@ -17,7 +17,6 @@ package commands
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/hugo/parser"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -27,6 +26,8 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/hugo/parser"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/fsync"
|
||||
"github.com/spf13/hugo/helpers"
|
||||
|
@ -53,6 +54,7 @@ built with love by spf13 and friends in Go.
|
|||
Complete documentation is available at http://gohugo.io/.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
InitializeConfig()
|
||||
watchConfig()
|
||||
build()
|
||||
},
|
||||
}
|
||||
|
@ -312,6 +314,18 @@ func InitializeConfig() {
|
|||
}
|
||||
}
|
||||
|
||||
func watchConfig() {
|
||||
viper.WatchConfig()
|
||||
viper.OnConfigChange(func(e fsnotify.Event) {
|
||||
fmt.Println("Config file changed:", e.Name)
|
||||
utils.CheckErr(buildSite(true))
|
||||
if !viper.GetBool("DisableLiveReload") {
|
||||
// Will block forever trying to write to a channel that nobody is reading if livereload isn't initalized
|
||||
livereload.ForceRefresh()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func build(watches ...bool) {
|
||||
utils.CheckErr(copyStatic(), fmt.Sprintf("Error copying static files to %s", helpers.AbsPathify(viper.GetString("PublishDir"))))
|
||||
watch := false
|
||||
|
|
|
@ -93,6 +93,7 @@ func server(cmd *cobra.Command, args []string) {
|
|||
|
||||
if viper.GetBool("watch") {
|
||||
serverWatch = true
|
||||
watchConfig()
|
||||
}
|
||||
|
||||
l, err := net.Listen("tcp", net.JoinHostPort(serverInterface, strconv.Itoa(serverPort)))
|
||||
|
|
|
@ -14,6 +14,7 @@ weight: 10
|
|||
* Have Jekyll site, but dreaming of porting it to Hugo? This release introduces a new `hugo import jekyll`command that makes this easier than ever. [1469](https://github.com/spf13/hugo/pull/1469)
|
||||
* We now use a custom-built `LazyFileReader` for reading file contents, which means we don't read media files in `/content` into memory anymore -- and file reading is now performed in parallel on multicore PCs. [1181](https://github.com/spf13/hugo/issues/1181)
|
||||
* Hugo is now built with `Go 1.5` which, among many other improvements, have fixed the last known data race in Hugo. [917] (https://github.com/spf13/hugo/issues/917)
|
||||
* Hugo now supports dynamic reloading of the config file when watching.
|
||||
* Lots of fixes and improvements in the template funcs:
|
||||
* The new `dict` function that could be used to pass maps into a template.[1463](https://github.com/spf13/hugo/pull/1463)
|
||||
* The new `pluralize` and `singularize` template funcs.
|
||||
|
@ -372,4 +373,3 @@ This release represents over 65 code commits from 6 different contributors.
|
|||
|
||||
## **0.5.0** June 25, 2013
|
||||
* Hugo is quite usable and able to build spf13.com
|
||||
|
||||
|
|
Loading…
Reference in a new issue