kiln/main.go

73 lines
1.2 KiB
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-29 20:42:27 +00:00
toAtom bool
site Site
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-29 20:42:27 +00:00
flag.BoolVar(&toAtom, "atom", false, "output Atom feed")
2020-09-30 01:30:50 +00:00
flag.StringVar(&site.Title, "title", "", "site title")
2020-09-29 20:42:27 +00:00
flag.StringVar(&site.URL, "url", "", "site URL")
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-30 01:30:50 +00:00
if err := site.load(); err != nil {
2020-09-22 20:42:14 +00:00
return err
}
2020-09-30 01:30:50 +00:00
site.sort()
if err := site.manipulate(); err != nil {
2020-09-22 20:42:14 +00:00
return err
}
2020-09-29 20:42:27 +00:00
if toAtom {
2020-09-30 01:30:50 +00:00
if err := site.createFeeds(); err != nil {
2020-09-29 20:42:27 +00:00
return err
}
}
2020-09-30 01:30:50 +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-30 01:30:50 +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()
}