1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-27 10:34:39 +01:00
gojekyll/server/livereload.go

25 lines
721 B
Go
Raw Normal View History

2017-06-22 23:37:46 +02:00
package server
import (
"io"
"github.com/jaschaephraim/lrserver"
2017-06-22 23:37:46 +02:00
)
// liveReloadScriptTag is inserted into the HTML page.
2017-06-22 23:37:46 +02:00
var liveReloadScriptTag = []byte(`<script src="http://localhost:35729/livereload.js"></script>`)
// StartLiveReloader starts the Live Reload server as a go routine, and returns immediately
func (s *Server) StartLiveReloader() error {
s.lr = lrserver.New(lrserver.DefaultName, lrserver.DefaultPort)
s.lr.SetStatusLog(nil)
go s.lr.ListenAndServe() // nolint: errcheck
return nil
2017-06-22 23:37:46 +02:00
}
2017-06-22 23:53:46 +02:00
// NewLiveReloadInjector returns a writer that injects the Live Reload JavaScript
2017-06-22 23:37:46 +02:00
// into its wrapped content.
func NewLiveReloadInjector(w io.Writer) io.Writer {
return TagInjector{w, liveReloadScriptTag}
}