mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-10-30 01:13:08 +00:00
Add -serve flag
This commit is contained in:
parent
27608b600e
commit
82a5490ff5
2
go.mod
2
go.mod
|
@ -1,3 +1,5 @@
|
|||
module kiln
|
||||
|
||||
go 1.15
|
||||
|
||||
require git.sr.ht/~adnano/gmi v0.0.0-20200928222852-855eff6d8802
|
||||
|
|
8
go.sum
Normal file
8
go.sum
Normal file
|
@ -0,0 +1,8 @@
|
|||
git.sr.ht/~adnano/gmi v0.0.0-20200928222852-855eff6d8802 h1:VAuDKKZWyq3/UkBuIeLEQ1qjRqiRfACfErdvBNdYz9A=
|
||||
git.sr.ht/~adnano/gmi v0.0.0-20200928222852-855eff6d8802/go.mod h1:4MWQDsleal4HRi/LuxxM6ymWJQikP3Gh7xZindVCHzg=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
2
kiln.go
2
kiln.go
|
@ -82,6 +82,7 @@ func (s *Site) Manipulate(dir *Directory) error {
|
|||
path := filepath.Join(dir.Path, "index.gmi")
|
||||
builder := &strings.Builder{}
|
||||
tmpl := s.Templates.Lookup("index.gmi")
|
||||
if tmpl != nil {
|
||||
if err := tmpl.Execute(builder, dir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -97,6 +98,7 @@ func (s *Site) Manipulate(dir *Directory) error {
|
|||
}
|
||||
dir.Index = page
|
||||
}
|
||||
}
|
||||
|
||||
// Manipulate pages
|
||||
for i := range dir.Pages {
|
||||
|
|
34
main.go
34
main.go
|
@ -1,16 +1,34 @@
|
|||
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() {
|
||||
if err := run(); err != nil {
|
||||
flag.Parse()
|
||||
if err := build(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if serveSite {
|
||||
serve()
|
||||
}
|
||||
}
|
||||
|
||||
func run() error {
|
||||
// build the site
|
||||
func build() error {
|
||||
site, err := LoadSite("src")
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -23,3 +41,15 @@ func run() error {
|
|||
}
|
||||
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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue