This commit is contained in:
Alex Yatskov 2022-05-08 10:19:48 -07:00
parent f1bdcbe961
commit ee6c1c82cb
3 changed files with 32 additions and 3 deletions

1
go.mod
View File

@ -5,5 +5,6 @@ go 1.16
require (
github.com/FooSoft/goldsmith v0.0.0-20220410034610-83530f1b2fe4
github.com/FooSoft/goldsmith-components v0.0.0-20220410175545-c35ca9cfd9d4
github.com/toqueteos/webbrowser v1.2.0
github.com/yuin/goldmark v1.4.12
)

2
go.sum
View File

@ -38,6 +38,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/tdewolff/minify/v2 v2.9.27/go.mod h1:L/bwPtsU/Xx30MxCndlClCMMiLbqROgkR4vZT+QIGXA=
github.com/tdewolff/parse/v2 v2.5.26/go.mod h1:WzaJpRSbwq++EIQHYIRTpbYKNA3gn9it1Ik++q4zyho=
github.com/tdewolff/test v1.0.6/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE=
github.com/toqueteos/webbrowser v1.2.0 h1:tVP/gpK69Fx+qMJKsLE7TD8LuGWPnEV71wBN9rrstGQ=
github.com/toqueteos/webbrowser v1.2.0/go.mod h1:XWoZq4cyp9WeUeak7w7LXRUQf1F1ATJMir8RTqb4ayM=
github.com/yuin/goldmark v1.4.4/go.mod h1:rmuwmfZ0+bvzB24eSC//bk1R1Zp3hM0OXYv/G2LIilg=
github.com/yuin/goldmark v1.4.12 h1:6hffw6vALvEDqJ19dOJvJKOoAOKe4NDaTqvd2sktGN0=
github.com/yuin/goldmark v1.4.12/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=

32
main.go
View File

@ -2,22 +2,29 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/signal"
"path/filepath"
"syscall"
"github.com/FooSoft/goldsmith"
"github.com/FooSoft/goldsmith-components/devserver"
"github.com/FooSoft/goldsmith-components/plugins/livejs"
"github.com/FooSoft/goldsmith-components/plugins/markdown"
"github.com/toqueteos/webbrowser"
"github.com/yuin/goldmark"
"github.com/yuin/goldmark/extension"
"github.com/yuin/goldmark/parser"
"github.com/yuin/goldmark/renderer/html"
)
type builder struct{}
type builder struct {
port int
browsing bool
}
func (self *builder) Build(contentDir, buildDir, cacheDir string) {
log.Print("building...")
@ -37,6 +44,11 @@ func (self *builder) Build(contentDir, buildDir, cacheDir string) {
for _, err := range errs {
log.Print(err)
}
if !self.browsing {
webbrowser.Open(fmt.Sprintf("http://127.0.0.1:%d", self.port))
self.browsing = true
}
}
func main() {
@ -63,6 +75,20 @@ func main() {
contentDir = filepath.Dir(requestPath)
}
b := new(builder)
devserver.DevServe(b, *port, contentDir, buildDir, "")
go func() {
b := &builder{port: *port}
devserver.DevServe(b, *port, contentDir, buildDir, "")
}()
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
for {
<-sigs
log.Println("terminating...")
break
}
if err := os.RemoveAll(buildDir); err != nil {
log.Fatal(err)
}
}