diff options
Diffstat (limited to 'transform')
-rw-r--r-- | transform/livereloadinject.go | 9 | ||||
-rw-r--r-- | transform/livereloadinject_test.go | 20 |
2 files changed, 22 insertions, 7 deletions
diff --git a/transform/livereloadinject.go b/transform/livereloadinject.go index 38e4e8cc9..2fb130c17 100644 --- a/transform/livereloadinject.go +++ b/transform/livereloadinject.go @@ -2,18 +2,13 @@ package transform 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) diff --git a/transform/livereloadinject_test.go b/transform/livereloadinject_test.go new file mode 100644 index 000000000..605f65954 --- /dev/null +++ b/transform/livereloadinject_test.go @@ -0,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())) + } +} |