summaryrefslogtreecommitdiffstats
path: root/transform/livereloadinject.go
diff options
context:
space:
mode:
Diffstat (limited to 'transform/livereloadinject.go')
-rw-r--r--transform/livereloadinject.go17
1 files changed, 5 insertions, 12 deletions
diff --git a/transform/livereloadinject.go b/transform/livereloadinject.go
index eb431f14a..bffedf040 100644
--- a/transform/livereloadinject.go
+++ b/transform/livereloadinject.go
@@ -2,29 +2,22 @@ package transform
import (
"bytes"
- jww "github.com/spf13/jwalterweatherman"
"github.com/spf13/viper"
)
-func LiveReloadInject(content []byte) (injected []byte) {
- defer func() {
- if r := recover(); r != nil {
- jww.ERROR.Println("Recovered in LiveReloadInject", r)
- injected = content
- }
- }()
+func LiveReloadInject(rw ContentReWriter) {
match := []byte("</body>")
port := viper.GetString("port")
replace := []byte(`<script>document.write('<script src="http://'
+ (location.host || 'localhost').split(':')[0]
+ ':` + port + `/livereload.js?mindelay=10"></'
+ 'script>')</script></body>`)
- newcontent := bytes.Replace(content, match, replace, -1)
+ newcontent := bytes.Replace(rw.Content(), match, replace, -1)
- if len(newcontent) == len(content) {
+ if len(newcontent) == len(rw.Content()) {
match := []byte("</BODY>")
- newcontent = bytes.Replace(content, match, replace, -1)
+ newcontent = bytes.Replace(rw.Content(), match, replace, -1)
}
- return newcontent
+ rw.Write(newcontent)
}