Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
alixander committed Nov 16, 2023
1 parent f328eb3 commit 490442a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions d2cli/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type watcher struct {
l net.Listener
staticFileServer http.Handler

boardpathMu sync.Mutex
wsclientsMu sync.Mutex
closing bool
wsclientsWG sync.WaitGroup
Expand Down Expand Up @@ -424,7 +425,9 @@ func (w *watcher) compileLoop(ctx context.Context) error {
}

fs := trackedFS{}
w.boardpathMu.Lock()
svg, _, err := compile(ctx, w.ms, w.plugins, &fs, w.layout, w.renderOpts, w.fontFamily, w.animateInterval, w.inputPath, w.outputPath, w.boardPath, w.bundle, w.forceAppendix, w.pw.Page)
w.boardpathMu.Unlock()
errs := ""
if err != nil {
if len(svg) > 0 {
Expand Down Expand Up @@ -507,13 +510,18 @@ func (w *watcher) handleRoot(hw http.ResponseWriter, r *http.Request) {
</body>
</html>`, filepath.Base(w.outputPath), w.devMode)

w.boardpathMu.Lock()
// if path is "/x.svg", we just want "x"
boardPath := strings.TrimPrefix(r.URL.Path, "/")
if idx := strings.LastIndexByte(boardPath, '.'); idx != -1 {
boardPath = boardPath[:idx]
}
recompile := false
if boardPath != w.boardPath {
w.boardPath = boardPath
}
w.boardpathMu.Unlock()
if recompile {
w.requestCompile()
}
}
Expand Down

0 comments on commit 490442a

Please sign in to comment.