kiln/main.go
2020-09-29 16:42:27 -04:00

72 lines
1.2 KiB
Go

package main
import (
"flag"
"log"
"time"
"git.sr.ht/~adnano/gmi"
)
var (
serveSite bool
toHtml bool
toAtom bool
site Site
)
func init() {
flag.BoolVar(&serveSite, "serve", false, "serve the site")
flag.BoolVar(&toHtml, "html", false, "output HTML")
flag.BoolVar(&toAtom, "atom", false, "output Atom feed")
flag.StringVar(&site.URL, "url", "", "site URL")
}
func main() {
flag.Parse()
if err := build(); err != nil {
log.Fatal(err)
}
if serveSite {
serve()
}
}
// build the site
func build() error {
if err := site.Load("src"); err != nil {
return err
}
site.Sort()
if err := site.Manipulate(site.Directory); err != nil {
return err
}
if toAtom {
if err := site.CreateFeeds(); 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()
}