From f733c83b1f212dafb6a0264ff3c827e2e21cd4c9 Mon Sep 17 00:00:00 2001 From: Facundo Olano Date: Wed, 28 Feb 2024 10:26:59 -0300 Subject: [PATCH] start devlog (#18) * remove sample posts * init first post * try not ignoring file creation events * draft why go section * more why go * why cli * finish first draft * reconnect with server after lost connection * corrections * more corrections * grammarly * remove docs section * update comment * remove doc index --- commands/serve.go | 9 +++-- docs/includes/nav.html | 1 - docs/src/blog/goodbye-markdown.md | 25 ------------ docs/src/blog/hello-org.org | 34 ---------------- docs/src/blog/index.html | 10 +---- docs/src/blog/why.org | 64 +++++++++++++++++++++++++++++++ docs/src/docs/index.html | 15 -------- docs/src/index.html | 16 +------- site/site.go | 25 +++++++----- 9 files changed, 88 insertions(+), 111 deletions(-) delete mode 100644 docs/src/blog/goodbye-markdown.md delete mode 100644 docs/src/blog/hello-org.org create mode 100644 docs/src/blog/why.org delete mode 100644 docs/src/docs/index.html 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) }