From 1df5053417f1492c7a1c0bd0855c58f39ee531b0 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 8 May 2022 12:06:31 -0700 Subject: [PATCH] Fix file paths --- main.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index a5eef3a..6e80895 100644 --- a/main.go +++ b/main.go @@ -32,8 +32,9 @@ var githubStyle string var githubFixup string type builder struct { - port int - browsing bool + port int + path string + open bool } func embedCss(file *goldsmith.File, doc *goquery.Document) error { @@ -69,9 +70,9 @@ func (self *builder) Build(contentDir, buildDir, cacheDir string) { log.Print(err) } - if !self.browsing { - webbrowser.Open(fmt.Sprintf("http://127.0.0.1:%d", self.port)) - self.browsing = true + if !self.open { + webbrowser.Open(fmt.Sprintf("http://127.0.0.1:%d/%s", self.port, self.path)) + self.open = true } } @@ -89,8 +90,17 @@ func main() { log.Fatal(err) } + var contentName string contentDir := requestPath if !info.IsDir() { + contentName = filepath.Base(requestPath) + contentExt := filepath.Ext(contentName) + switch contentExt { + case ".md", ".markdown": + contentName = strings.TrimSuffix(contentName, contentExt) + contentName += ".html" + } + contentDir = filepath.Dir(requestPath) } @@ -107,7 +117,7 @@ func main() { }() go func() { - b := &builder{port: *port} + b := &builder{port: *port, path: contentName} devserver.DevServe(b, *port, contentDir, buildDir, "") }()