ref: ef4dfcec6cf17308e2816ef29801f01c3cf6fcbb
parent: 0f438d185272f9c14b8aa64dd0cb2d0cef260361
author: Kato Kazuyoshi <[email protected]>
date: Tue Oct 13 20:41:54 EDT 2015
Load livereload.js from "/" Fix #1406 Instead of loading the file from http://localhost:port/, it can be loaded from /.
--- a/transform/livereloadinject.go
+++ b/transform/livereloadinject.go
@@ -2,18 +2,13 @@
import (
"bytes"
- "github.com/spf13/viper"
)
func LiveReloadInject(ct contentTransformer) {
match := []byte("</body>")
- port := viper.GetString("port")
- replace := []byte(`<script data-no-instant>document.write('<script src="http://'
- + (location.host || 'localhost').split(':')[0]
- + ':` + port + `/livereload.js?mindelay=10"></'
- + 'script>')</script></body>`)
- newcontent := bytes.Replace(ct.Content(), match, replace, -1)
+ replace := []byte(`<script data-no-instant>document.write('<script src="/livereload.js?mindelay=10"></' + 'script>')</script></body>`)
+ newcontent := bytes.Replace(ct.Content(), match, replace, -1)
if len(newcontent) == len(ct.Content()) {
match := []byte("</BODY>")
newcontent = bytes.Replace(ct.Content(), match, replace, -1)
--- /dev/null
+++ b/transform/livereloadinject_test.go
@@ -1,0 +1,20 @@
+package transform
+
+import (
+ "bytes"
+ "github.com/spf13/hugo/helpers"
+ "testing"
+)
+
+func TestLiveReloadInject(t *testing.T) {
+ out := new(bytes.Buffer)
+ in := helpers.StringToReader("</body>")
+
+ tr := NewChain(LiveReloadInject)
+ tr.Apply(out, in, []byte("path"))
+
+ expected := `<script data-no-instant>document.write('<script src="/livereload.js?mindelay=10"></' + 'script>')</script></body>`
+ if string(out.Bytes()) != expected {
+ t.Errorf("Expected %s got %s", expected, string(out.Bytes()))
+ }
+}