|
|
|
@ -309,6 +309,13 @@ func (ch *CaddyHugo) doc(r *http.Request) (*docref, error) { |
|
|
|
|
doc: acedoc.NewString(string(contents)), |
|
|
|
|
tmpdir: tmpdir, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
err = ref.doc.LogToFile(path.Join(ch.Site.Root, "logs", r.URL.Path[len("/hugo/edit/"):])) |
|
|
|
|
if err != nil { |
|
|
|
|
fmt.Println(err) |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ch.docs[name] = ref |
|
|
|
|
|
|
|
|
|
hugoCmd := exec.Command("hugo", "--watch", "-D", "-d", ref.tmpdir) |
|
|
|
@ -347,11 +354,12 @@ func (ch *CaddyHugo) doc(r *http.Request) (*docref, error) { |
|
|
|
|
idleTime := time.Duration(idleTicks) * WebsocketFileTicker |
|
|
|
|
if idleTime >= IdleWebsocketTimeout { |
|
|
|
|
err := ch.Publish() |
|
|
|
|
fmt.Printf("idle for %v, quitting", idleTime) |
|
|
|
|
fmt.Printf("idle for %v, quitting\n", idleTime) |
|
|
|
|
if err != nil { |
|
|
|
|
fmt.Printf(", error publishing: %v\n", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ref.doc.Close() |
|
|
|
|
os.RemoveAll(tmpdir) |
|
|
|
|
delete(ch.docs, name) |
|
|
|
|
ch.mtx.Unlock() |
|
|
|
@ -421,6 +429,7 @@ func (ch *CaddyHugo) DeltaWebsocket(w http.ResponseWriter, r *http.Request) (int |
|
|
|
|
|
|
|
|
|
defer func() { |
|
|
|
|
ch.mtx.Lock() |
|
|
|
|
client.Close() |
|
|
|
|
doc.clients-- |
|
|
|
|
ch.mtx.Unlock() |
|
|
|
|
}() |
|
|
|
|