mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-10-30 01:13:08 +00:00
56 lines
804 B
Go
56 lines
804 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"time"
|
|
|
|
"git.sr.ht/~adnano/gmi"
|
|
)
|
|
|
|
var (
|
|
serveSite bool
|
|
)
|
|
|
|
func init() {
|
|
flag.BoolVar(&serveSite, "serve", false, "serve the site")
|
|
}
|
|
|
|
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
|
|
}
|
|
if err := site.Manipulate(site.Directory); err != nil {
|
|
return err
|
|
}
|
|
if err := site.Write("dst"); 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()
|
|
}
|