Cleanup
This commit is contained in:
parent
60617398f2
commit
f5ac804c2b
23
main.go
23
main.go
@ -71,29 +71,38 @@ func (self *builder) Build(contentDir, buildDir, cacheDir string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !self.open {
|
if !self.open {
|
||||||
webbrowser.Open(fmt.Sprintf("http://127.0.0.1:%d/%s", self.port, self.path))
|
url := fmt.Sprintf("http://127.0.0.1:%d/%s", self.port, self.path)
|
||||||
|
log.Printf("opening %s in browser...", url)
|
||||||
|
webbrowser.Open(url)
|
||||||
self.open = true
|
self.open = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
flag.Usage = func() {
|
||||||
|
fmt.Fprintf(os.Stderr, "Usage %s [options] [path]\n\n", filepath.Base(os.Args[0]))
|
||||||
|
fmt.Fprintln(os.Stderr, "Parameters:")
|
||||||
|
flag.PrintDefaults()
|
||||||
|
}
|
||||||
|
|
||||||
port := flag.Int("port", 8080, "port")
|
port := flag.Int("port", 8080, "port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if flag.NArg() != 1 {
|
if flag.NArg() != 1 {
|
||||||
log.Fatal("unexpected number of arguments")
|
flag.Usage()
|
||||||
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
requestPath := flag.Arg(0)
|
path := flag.Arg(0)
|
||||||
info, err := os.Stat(requestPath)
|
info, err := os.Stat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var contentName string
|
var contentName string
|
||||||
contentDir := requestPath
|
contentDir := path
|
||||||
if !info.IsDir() {
|
if !info.IsDir() {
|
||||||
contentName = filepath.Base(requestPath)
|
contentName = filepath.Base(path)
|
||||||
contentExt := filepath.Ext(contentName)
|
contentExt := filepath.Ext(contentName)
|
||||||
switch contentExt {
|
switch contentExt {
|
||||||
case ".md", ".markdown":
|
case ".md", ".markdown":
|
||||||
@ -101,7 +110,7 @@ func main() {
|
|||||||
contentName += ".html"
|
contentName += ".html"
|
||||||
}
|
}
|
||||||
|
|
||||||
contentDir = filepath.Dir(requestPath)
|
contentDir = filepath.Dir(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
buildDir, err := ioutil.TempDir("", "mvd-*")
|
buildDir, err := ioutil.TempDir("", "mvd-*")
|
||||||
|
Loading…
Reference in New Issue
Block a user