mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-20 13:21:08 +00: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,19 +14,20 @@ 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.
|
||||
* 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.
|
||||
* The new `base64Decode` and `base64Encode` template funcs.
|
||||
* The `sort` template func now accepts field/key chaining arguments and pointer values. [1330](https://github.com/spf13/hugo/issues/1330)
|
||||
* Several fixes for `slicestr` and `substr`, most importantly, they now have full `utf-8`-support. [1190](https://github.com/spf13/hugo/issues/1190) [1333](https://github.com/spf13/hugo/issues/1333) [1347](https://github.com/spf13/hugo/issues/1347)
|
||||
* Several fixes for `slicestr` and `substr`, most importantly, they now have full `utf-8`-support. [1190](https://github.com/spf13/hugo/issues/1190) [1333](https://github.com/spf13/hugo/issues/1333) [1347](https://github.com/spf13/hugo/issues/1347)
|
||||
* The new `last` template function allows the user to select the last `N` items of a slice. [1148](https://github.com/spf13/hugo/issues/1148)
|
||||
* The new `after` func allows the user to select the items after the `Nth` item. [1200] (https://github.com/spf13/hugo/pull/1200)
|
||||
* Add `time.Time` type support to the `where` func.
|
||||
* It is now possible to use constructs like `where Values ".Param.key" nil` to filter pages that doesn't have a particular parameter. [1232](https://github.com/spf13/hugo/issues/1232)
|
||||
* `getJSON`/`getCSV`: Add retry on invalid content. [1166](https://github.com/spf13/hugo/issues/1166)
|
||||
* The new `readDir` func lists local files. [1204](https://github.com/spf13/hugo/pull/1204)
|
||||
* The new `Param` convenience method on `Page` and `Node` can be used to get the most specific parameter value for a given key. [1462](https://github.com/spf13/hugo/issues/1462)
|
||||
* The new `Param` convenience method on `Page` and `Node` can be used to get the most specific parameter value for a given key. [1462](https://github.com/spf13/hugo/issues/1462)
|
||||
* Several new Blackfriday options are added:
|
||||
* Option to disable Blackfriday's `Smartypants`.
|
||||
* Option for Blackfriday to open links in a new window/tab. [1220](https://github.com/spf13/hugo/issues/1220)
|
||||
|
@ -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