mirror of
https://github.com/danog/gojekyll.git
synced 2024-12-03 11:57:45 +01:00
De-clutter livereloader output
This commit is contained in:
parent
5917e94fe7
commit
dd2980d2c9
@ -2,6 +2,8 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"github.com/jaschaephraim/lrserver"
|
"github.com/jaschaephraim/lrserver"
|
||||||
)
|
)
|
||||||
@ -9,11 +11,13 @@ import (
|
|||||||
// liveReloadScriptTag is inserted into the HTML page.
|
// liveReloadScriptTag is inserted into the HTML page.
|
||||||
var liveReloadScriptTag = []byte(`<script src="http://localhost:35729/livereload.js"></script>`)
|
var liveReloadScriptTag = []byte(`<script src="http://localhost:35729/livereload.js"></script>`)
|
||||||
|
|
||||||
// StartLiveReloader starts the Live Reload server as a go routine, and returns immediately
|
// startLiveReloader starts the Live Reload server as a go routine, and returns immediately
|
||||||
func (s *Server) StartLiveReloader() error {
|
func (s *Server) startLiveReloader() error {
|
||||||
s.lr = lrserver.New(lrserver.DefaultName, lrserver.DefaultPort)
|
lr := lrserver.New(lrserver.DefaultName, lrserver.DefaultPort)
|
||||||
s.lr.SetStatusLog(nil)
|
s.lr = lr
|
||||||
go s.lr.ListenAndServe() // nolint: errcheck
|
lr.SetStatusLog(nil)
|
||||||
|
lr.ErrorLog().SetOutput(outputFilter{os.Stdout})
|
||||||
|
go lr.ListenAndServe() // nolint: errcheck
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,3 +26,16 @@ func (s *Server) StartLiveReloader() error {
|
|||||||
func NewLiveReloadInjector(w io.Writer) io.Writer {
|
func NewLiveReloadInjector(w io.Writer) io.Writer {
|
||||||
return TagInjector{w, liveReloadScriptTag}
|
return TagInjector{w, liveReloadScriptTag}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove the lines that match the exclusion pattern.
|
||||||
|
// TODO submit an upstream PR to make this unnecessary
|
||||||
|
type outputFilter struct{ w *os.File }
|
||||||
|
|
||||||
|
var excludeRE = regexp.MustCompile(`websocket: close 1006 \(abnormal closure\): unexpected EOF`)
|
||||||
|
|
||||||
|
func (w outputFilter) Write(b []byte) (int, error) {
|
||||||
|
if excludeRE.Match(b) {
|
||||||
|
return len(b), nil
|
||||||
|
}
|
||||||
|
return w.w.Write(b)
|
||||||
|
}
|
||||||
|
@ -32,7 +32,7 @@ func (s *Server) Run(open bool, logger func(label, value string)) error {
|
|||||||
address := fmt.Sprintf("%s:%d", cfg.Host, cfg.Port)
|
address := fmt.Sprintf("%s:%d", cfg.Host, cfg.Port)
|
||||||
logger("Server address:", "http://"+address+"/")
|
logger("Server address:", "http://"+address+"/")
|
||||||
if cfg.Watch {
|
if cfg.Watch {
|
||||||
if err := s.StartLiveReloader(); err != nil {
|
if err := s.startLiveReloader(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := s.watchReload(); err != nil {
|
if err := s.watchReload(); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user