shithub: hugo

Download patch

ref: bccf957e36346390336b172d10aae60bde90e397
parent: 488966dcb2600626563659f2ffbee43181e36a2d
author: spf13 <[email protected]>
date: Mon Nov 9 18:31:52 EST 2015

Add support for dynamic reloading of config file when watching

--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -17,7 +17,6 @@
 
 import (
 	"fmt"
-	"github.com/spf13/hugo/parser"
 	"io/ioutil"
 	"net/http"
 	"os"
@@ -27,6 +26,8 @@
 	"sync"
 	"time"
 
+	"github.com/spf13/hugo/parser"
+
 	"github.com/spf13/cobra"
 	"github.com/spf13/fsync"
 	"github.com/spf13/hugo/helpers"
@@ -53,6 +54,7 @@
 Complete documentation is available at http://gohugo.io/.`,
 	Run: func(cmd *cobra.Command, args []string) {
 		InitializeConfig()
+		watchConfig()
 		build()
 	},
 }
@@ -310,6 +312,18 @@
 		jww.ERROR.Printf("Current theme does not support Hugo version %s. Minimum version required is %s\n",
 			helpers.HugoReleaseVersion(), minVersion)
 	}
+}
+
+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) {
--- a/commands/server.go
+++ b/commands/server.go
@@ -93,6 +93,7 @@
 
 	if viper.GetBool("watch") {
 		serverWatch = true
+		watchConfig()
 	}
 
 	l, err := net.Listen("tcp", net.JoinHostPort(serverInterface, strconv.Itoa(serverPort)))
--- a/docs/content/meta/release-notes.md
+++ b/docs/content/meta/release-notes.md
@@ -14,12 +14,13 @@
 * 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.
@@ -26,7 +27,7 @@
 	* 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 @@
 
 ## **0.5.0** June 25, 2013
   * Hugo is quite usable and able to build spf13.com
-