diff --git a/commands/serve.go b/commands/serve.go index e6641e1..52ec2ea 100644 --- a/commands/serve.go +++ b/commands/serve.go @@ -6,6 +6,7 @@ import ( "net/http" "os" "path/filepath" + "strings" "sync/atomic" "time" @@ -69,6 +70,7 @@ func makeServerEventsHandler(broker *EventBroker) http.HandlerFunc { // send an event to the connected client. // data\n\n just means send an empty, unnamed event // since we only need to support the single reload operation. + fmt.Fprint(res, "retry: 1000\n") fmt.Fprint(res, "data\n\n") res.(http.Flusher).Flush() case <-req.Context().Done(): @@ -104,9 +106,10 @@ func setupWatcher(config *config.Config) (*fsnotify.Watcher, *EventBroker, error return } - // chmod events are noisy, ignore them. also skip create events - // which we assume meaningless until the write that comes next - if event.Has(fsnotify.Chmod) || event.Has(fsnotify.Create) { + // chmod events are noisy, ignore them. + // Also ignore dot file events, which are usually spurious (e.g .DS_Store, emacs temp files) + isDotFile := strings.HasPrefix(filepath.Base(event.Name), ".") + if event.Has(fsnotify.Chmod) || isDotFile { continue } diff --git a/docs/includes/nav.html b/docs/includes/nav.html index 7d3991a..360a7c5 100644 --- a/docs/includes/nav.html +++ b/docs/includes/nav.html @@ -2,7 +2,6 @@ {{ site.config.name }} tutorial devlog - docs diff --git a/docs/src/index.html b/docs/src/index.html index f992bc0..e7a8e36 100644 --- a/docs/src/index.html +++ b/docs/src/index.html @@ -51,23 +51,9 @@ $ jorge serve

Devlog

-Coming soon! - -{% comment %} -{% for post in site.posts limit:3 %} +{% for post in site.posts | reverse limit:5 %} {% include post_preview.html %} {% endfor %}

See the full blog archive or subscribe to the feed.

-{% endcomment %} - -

Docs

-Coming soon! - diff --git a/site/site.go b/site/site.go index 3532944..538d674 100644 --- a/site/site.go +++ b/site/site.go @@ -387,17 +387,22 @@ func (site *Site) injectLiveReload(extension string, contentReader io.Reader) (i const JS_SNIPPET = ` const url = '%s/_events/' -const eventSource = new EventSource(url); - -eventSource.onmessage = function () { - location.reload() -}; -window.onbeforeunload = function() { - eventSource.close(); +var eventSource; +function newSSE() { + console.log("connecting to server events"); + eventSource = new EventSource(url); + eventSource.onmessage = function () { + location.reload() + }; + window.onbeforeunload = function() { + eventSource.close(); + } + eventSource.onerror = function (event) { + console.error('An error occurred:', event); + setTimeout(newSSE, 1000) + }; } -eventSource.onerror = function (event) { - console.error('An error occurred:', event) -};` +newSSE();` script := fmt.Sprintf(JS_SNIPPET, site.Config.SiteUrl) return markup.InjectScript(contentReader, script) }