diff --git a/docs/src/blog/a-site-server-with-live-reload.org b/docs/src/blog/a-site-server-with-live-reload.org index c7d4793..9e6f456 100644 --- a/docs/src/blog/a-site-server-with-live-reload.org +++ b/docs/src/blog/a-site-server-with-live-reload.org @@ -193,10 +193,10 @@ func (site *site) build() error { return os.MkdirAll(targetPath, FILE_RW_MODE) } -- // if it's a file render or copy it at the target +- // if it's a file render or copy it to the target - return site.buildFile(path, targetPath) + // if it's a file send the path to a worker -+ // to render or copy it at the target ++ // to render or copy it to the target + files <- path + return nil }) @@ -249,7 +249,8 @@ var eventSource; function newSSE() { console.log("connecting to server events"); - eventSource = new EventSource('http://localhost:4001/_events/'); + const url = location.origin + '/_events/'; + eventSource = new EventSource(url); // when the server sends an event, refresh the page eventSource.onmessage = function () { diff --git a/site/site.go b/site/site.go index 95816d6..570b0a7 100644 --- a/site/site.go +++ b/site/site.go @@ -434,7 +434,7 @@ func (site *site) injectLiveReload(extension string, contentReader io.Reader) (i } const JS_SNIPPET = ` -const url = '%s/_events/' +const url = location.origin + '/_events/' var eventSource; function newSSE() { console.log("connecting to server events"); @@ -452,6 +452,5 @@ function newSSE() { }; } newSSE();` - script := fmt.Sprintf(JS_SNIPPET, site.config.SiteUrl) - return markup.InjectScript(contentReader, script) + return markup.InjectScript(contentReader, JS_SNIPPET) }