diff options
author | Bjørn Erik Pedersen <[email protected]> | 2016-03-24 14:05:08 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2016-03-24 14:05:08 +0100 |
commit | 218fceac358ad3c76482ff009be7ccf4df6ce988 (patch) | |
tree | c4523f0efe341fcca3a10f3edaa4e9337f2c26b0 /livereload | |
parent | e467d23374f0e8db0bb7357725a156805bc1d662 (diff) | |
download | hugo-218fceac358ad3c76482ff009be7ccf4df6ce988.tar.gz hugo-218fceac358ad3c76482ff009be7ccf4df6ce988.zip |
livereload: Add missing GoDoc
Diffstat (limited to 'livereload')
-rw-r--r-- | livereload/livereload.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/livereload/livereload.go b/livereload/livereload.go index c5eeab887..a3309c49a 100644 --- a/livereload/livereload.go +++ b/livereload/livereload.go @@ -45,6 +45,8 @@ import ( var upgrader = &websocket.Upgrader{ReadBufferSize: 1024, WriteBufferSize: 1024} +// Handler is a HandlerFunc handling the livereload +// Websocket interaction. func Handler(w http.ResponseWriter, r *http.Request) { ws, err := upgrader.Upgrade(w, r, nil) if err != nil { @@ -57,21 +59,26 @@ func Handler(w http.ResponseWriter, r *http.Request) { c.reader() } +// Initialize starts the Websocket Hub handling live reloads. func Initialize() { go wsHub.run() } +// ForceRefresh tells livereload to force a hard refresh. func ForceRefresh() { - // Tell livereload a js file changed to force a hard refresh RefreshPath("/x.js") } +// RefreshPath tells livereload to refresh only the given path. +// If that path points to a CSS stylesheet or an image, only the changes +// will be updated in the browser, not the entire page. func RefreshPath(s string) { // Tell livereload a file has changed - will force a hard refresh if not CSS or an image urlPath := strings.Replace(s, "\\", "/", -1) // If path has backslashes on Windows, make path work for URL wsHub.broadcast <- []byte(`{"command":"reload","path":"` + urlPath + "\"" + `,"originalPath":"","liveCSS":true,"liveImg":true}`) } +// ServeJS serves the liverreload.js who's reference is injected into the page. func ServeJS(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/javascript") w.Write(livereloadJS) |