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.Title, "title", "", "site title") 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(); err != nil { return err } site.sort() if err := site.manipulate(); 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() }