Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"flag"
"fmt"
"html/template"
textTmpl "text/template"
"io"
"io/fs"
"log"
Expand All @@ -18,6 +17,7 @@ import (
"runtime"
"strings"
"sync"
textTmpl "text/template"

_ "embed"

Expand Down Expand Up @@ -695,7 +695,6 @@ func (af *AlvuFile) FlushFile() {
layoutTemplateData = `<body>{{.Content}}</body>`
}

layoutTemplateData = _injectLiveReload(&layoutTemplateData)
toHtml.Reset()
layout.Parse(layoutTemplateData)
layout.Execute(&toHtml, layoutData)
Expand All @@ -719,9 +718,16 @@ func (af *AlvuFile) FlushFile() {
t.Parse(string(data))

f.Seek(0, 0)
f.Truncate(0)

err = t.Execute(f, renderData)
bail(err)

// inject live reload script if serve flag is enabled
if *serveFlag {
liveReloadScript := _getLiveReloadScript()
f.WriteString(liveReloadScript)
}
}

func NewHook() *lua.LState {
Expand Down Expand Up @@ -1044,11 +1050,8 @@ func (w *Watcher) StartWatching() {
}()
}

func _injectLiveReload(layoutHTML *string) string {
if !*serveFlag {
return *layoutHTML
}
return *layoutHTML + `<script>
func _getLiveReloadScript() string {
return `<script>
const socket = new WebSocket("ws://localhost:3000/ws");

// Connection opened
Expand Down