kiln/main.go

64 lines
995 B
Go
Raw Normal View History

2020-09-22 20:42:14 +00:00
package main
import (
2020-09-28 23:54:48 +00:00
"flag"
2020-09-22 20:42:14 +00:00
"log"
2020-09-28 23:54:48 +00:00
"time"
"git.sr.ht/~adnano/gmi"
)
var (
serveSite bool
2020-09-29 14:57:15 +00:00
toHtml bool
2020-09-22 20:42:14 +00:00
)
2020-09-28 23:54:48 +00:00
func init() {
flag.BoolVar(&serveSite, "serve", false, "serve the site")
2020-09-29 14:57:15 +00:00
flag.BoolVar(&toHtml, "html", false, "output HTML")
2020-09-28 23:54:48 +00:00
}
2020-09-22 20:42:14 +00:00
func main() {
2020-09-28 23:54:48 +00:00
flag.Parse()
if err := build(); err != nil {
2020-09-22 20:42:14 +00:00
log.Fatal(err)
}
2020-09-28 23:54:48 +00:00
if serveSite {
serve()
}
2020-09-22 20:42:14 +00:00
}
2020-09-28 23:54:48 +00:00
// build the site
func build() error {
2020-09-22 23:46:30 +00:00
site, err := LoadSite("src")
2020-09-22 20:42:14 +00:00
if err != nil {
return err
}
2020-09-29 15:22:54 +00:00
site.Sort()
2020-09-23 01:11:56 +00:00
if err := site.Manipulate(site.Directory); err != nil {
2020-09-22 20:42:14 +00:00
return err
}
2020-09-29 15:22:54 +00:00
if err := site.Write("dst", OutputGemini); err != nil {
2020-09-22 20:42:14 +00:00
return err
}
2020-09-29 14:57:15 +00:00
if toHtml {
2020-09-29 15:22:54 +00:00
if err := site.Write("dst.html", OutputHTML); err != nil {
2020-09-29 14:57:15 +00:00
return err
}
}
2020-09-22 20:42:14 +00:00
return nil
}
2020-09-28 23:54:48 +00:00
// 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()
}