diff options
author | spf13 <steve.francia@gmail.com> | 2014-05-16 17:49:27 -0400 |
---|---|---|
committer | spf13 <steve.francia@gmail.com> | 2014-05-16 17:49:27 -0400 |
commit | be1ee220327073d7304621b4386df9d6252bb837 (patch) | |
tree | 2554a6d39e1bcce80c52041c2540fc09fd964ebb /transform | |
parent | 60ed5bda2b3d1c6f2d67287a9d7a434f588cdb14 (diff) |
Proper integration of live reload with automatic injection
Diffstat (limited to 'transform')
-rw-r--r-- | transform/livereloadinject.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/transform/livereloadinject.go b/transform/livereloadinject.go new file mode 100644 index 000000000..a84f850ad --- /dev/null +++ b/transform/livereloadinject.go @@ -0,0 +1,19 @@ +package transform + +import "bytes" + +func LiveReloadInject(content []byte) []byte { + match := []byte("</body>") + replace := []byte(`<script>document.write('<script src="http://' + + (location.host || 'localhost').split(':')[0] + + ':1313/livereload.js?mindelay=10"></' + + 'script>')</script></body>`) + newcontent := bytes.Replace(content, match, replace, -1) + + if len(newcontent) == len(content) { + match := []byte("</BODY>") + newcontent = bytes.Replace(content, match, replace, -1) + } + + return newcontent +} |