shithub: hugo

Download patch

ref: 7a8b754cada398241fc2d58d63ce58551f6c734c
parent: 4076d77029e0705f9e9aa43a347b033dbc2d3cc9
author: spf13 <[email protected]>
date: Wed May 28 15:01:24 EDT 2014

Fixed #301. LiveReload works on any port now.

--- a/commands/server.go
+++ b/commands/server.go
@@ -83,6 +83,8 @@
 		serverPort = sp.Port
 	}
 
+	viper.Set("port", serverPort)
+
 	if serverAppend {
 		viper.Set("BaseUrl", strings.TrimSuffix(BaseUrl, "/")+":"+strconv.Itoa(serverPort))
 	} else {
--- a/transform/livereloadinject.go
+++ b/transform/livereloadinject.go
@@ -1,12 +1,17 @@
 package transform
 
-import "bytes"
+import (
+	"bytes"
 
+	"github.com/spf13/viper"
+)
+
 func LiveReloadInject(content []byte) []byte {
 	match := []byte("</body>")
+	port := viper.GetString("port")
 	replace := []byte(`<script>document.write('<script src="http://'
         + (location.host || 'localhost').split(':')[0]
-        + ':1313/livereload.js?mindelay=10"></'
+		+ ':` + port + `/livereload.js?mindelay=10"></'
         + 'script>')</script></body>`)
 	newcontent := bytes.Replace(content, match, replace, -1)