Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbep <bjorn.erik.pedersen@gmail.com>2015-03-18 02:36:48 +0300
committerbep <bjorn.erik.pedersen@gmail.com>2015-03-18 19:05:54 +0300
commit98ee69bce207a4c2a7c2ffca2b3e7c0ccdd6e8c9 (patch)
treeebfb45ab42cad8a14dc44f8bacb92b47cfd12b94 /transform/livereloadinject.go
parent9688ed2585fcea732095baeb4006c5c96875447c (diff)
Write to rotating ContentReWriter in transformer chain
This commit adds the interface ContentReWriter in the tranformer chain. This is backed by two pooled byte buffers, alternating between being the reader or the writer. This keeps the performance characteristic of the old implementation, but in a thread safe way. Fixes #911 Benchmark old vs new: benchmark old ns/op new ns/op delta BenchmarkAbsURL 17614 17384 -1.31% BenchmarkXMLAbsURL 9431 9248 -1.94% benchmark old allocs new allocs delta BenchmarkAbsURL 24 28 +16.67% BenchmarkXMLAbsURL 12 14 +16.67% benchmark old bytes new bytes delta BenchmarkAbsURL 3295 3424 +3.92% BenchmarkXMLAbsURL 1954 1987 +1.69%
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)
}