This repository has been archived on 2025-03-15. You can view files and clone it, but cannot push or open issues or pull requests.
hui/internal/ui/preview.go
2024-07-31 19:10:32 +02:00

35 lines
554 B
Go

package ui
import (
"os/exec"
"runtime"
"varia.zone/hui/internal/model"
)
func openLocalhost(url string) error {
var cmd string
var args []string
switch runtime.GOOS {
case "darwin":
cmd = "open"
default:
cmd = "xdg-open"
}
args = append(args, url)
return exec.Command(cmd, args...).Start()
}
// PreviewSite previews the site locally.
func PreviewSite(m *model.Model) error {
// TODO: run serve with generated port
// ensure no port clash by checking model
url := "http://localhost:1313"
openLocalhost(url)
return nil
}