kiln/main.go
2020-09-29 11:22:54 -04:00

64 lines
995 B
Go

package main
import (
"flag"
"log"
"time"
"git.sr.ht/~adnano/gmi"
)
var (
serveSite bool
toHtml bool
)
func init() {
flag.BoolVar(&serveSite, "serve", false, "serve the site")
flag.BoolVar(&toHtml, "html", false, "output HTML")
}
func main() {
flag.Parse()
if err := build(); err != nil {
log.Fatal(err)
}
if serveSite {
serve()
}
}
// build the site
func build() error {
site, err := LoadSite("src")
if err != nil {
return err
}
site.Sort()
if err := site.Manipulate(site.Directory); err != nil {
return err
}
if err := site.Write("dst", OutputGemini); err != nil {
return err
}
if toHtml {
if err := site.Write("dst.html", OutputHTML); err != nil {
return err
}
}
return nil
}
// serve the site
func serve() error {
server := &gmi.Server{}
cert, err := gmi.NewCertificate("localhost", time.Hour)
if err != nil {
return err
}
server.Certificate = cert
server.Handler = gmi.FileServer(gmi.Dir("dst"))
return server.ListenAndServe()
}