summaryrefslogtreecommitdiffstats
path: root/transform/livereloadinject.go
diff options
context:
space:
mode:
Diffstat (limited to 'transform/livereloadinject.go')
-rw-r--r--transform/livereloadinject.go19
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
+}