pr comments

This commit is contained in:
Alexander Wang 2023-07-29 09:16:45 -07:00
parent 7bea22e504
commit 65f97fc7be
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
2 changed files with 26 additions and 18 deletions

View file

@ -443,8 +443,10 @@ func (w *watcher) handleRoot(hw http.ResponseWriter, r *http.Request) {
</html>`, filepath.Base(w.outputPath), w.devMode)
// if path is "/x.svg", we just want "x"
split := strings.Split(strings.TrimPrefix(r.URL.Path, "/"), ".")
boardPath := strings.Join(split[:len(split)-1], ".")
boardPath := strings.TrimPrefix(r.URL.Path, "/")
if idx := strings.LastIndexByte(boardPath, '.'); idx != -1 {
boardPath = boardPath[:idx]
}
if boardPath != w.boardPath {
w.boardPath = boardPath
w.requestCompile()

View file

@ -81,53 +81,59 @@ func (d *Diagram) GetBoard(boardPath string) *Diagram {
return d
}
head := path[0]
return d.getBoard(path)
}
func (d *Diagram) getBoard(boardPath []string) *Diagram {
head := boardPath[0]
if head == "index" {
return d
}
switch head {
case "layers", "scenarios", "steps":
if len(path) < 2 {
case "layers":
if len(boardPath) < 2 {
return nil
}
}
switch head {
case "layers":
for _, b := range d.Layers {
if b.Name == path[1] {
return b.GetBoard(strings.Join(path[2:], string(os.PathSeparator)))
if b.Name == boardPath[1] {
return b.getBoard(boardPath[2:])
}
}
case "scenarios":
if len(boardPath) < 2 {
return nil
}
for _, b := range d.Scenarios {
if b.Name == path[1] {
return b.GetBoard(strings.Join(path[2:], string(os.PathSeparator)))
if b.Name == boardPath[1] {
return b.getBoard(boardPath[2:])
}
}
case "steps":
if len(boardPath) < 2 {
return nil
}
for _, b := range d.Steps {
if b.Name == path[1] {
return b.GetBoard(strings.Join(path[2:], string(os.PathSeparator)))
if b.Name == boardPath[1] {
return b.getBoard(boardPath[2:])
}
}
}
for _, b := range d.Layers {
if b.Name == head {
return b.GetBoard(strings.Join(path[1:], string(os.PathSeparator)))
return b.getBoard(boardPath[2:])
}
}
for _, b := range d.Scenarios {
if b.Name == head {
return b.GetBoard(strings.Join(path[1:], string(os.PathSeparator)))
return b.getBoard(boardPath[2:])
}
}
for _, b := range d.Steps {
if b.Name == head {
return b.GetBoard(strings.Join(path[1:], string(os.PathSeparator)))
return b.getBoard(boardPath[2:])
}
}
return nil