2020-12-04 12:50:20 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-12-31 13:28:09 +01:00
|
|
|
"errors"
|
2020-12-04 12:50:20 +01:00
|
|
|
"flag"
|
2020-12-04 16:52:25 +01:00
|
|
|
"io/ioutil"
|
2020-12-04 12:50:20 +01:00
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
2020-12-21 07:36:45 +01:00
|
|
|
"git.sr.ht/~ewintr/shitty-ssg/cmd/ssg/site"
|
2020-12-04 12:50:20 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-12-31 13:28:09 +01:00
|
|
|
siteName = flag.String("site", "ewnl", "site id, either 'ewnl' or 'vkvnl'")
|
2020-12-04 12:50:20 +01:00
|
|
|
resources = flag.String("resources", "./resources", "folder with templates and other resources")
|
|
|
|
content = flag.String("content", "./content,/projectx", "comma separated list of folders search for content")
|
2020-12-04 16:52:25 +01:00
|
|
|
statics = flag.String("statics", "./statics", "folder with static content")
|
2020-12-04 12:50:20 +01:00
|
|
|
public = flag.String("public", "./public", "target folder for generated site")
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
2020-12-31 13:28:09 +01:00
|
|
|
if *siteName == "" || *resources == "" || *content == "" || *public == "" || *statics == "" {
|
2020-12-04 12:50:20 +01:00
|
|
|
log.Fatal("missing parameter")
|
|
|
|
}
|
|
|
|
|
2020-12-31 13:28:09 +01:00
|
|
|
var siteId site.SiteID
|
|
|
|
switch *siteName {
|
|
|
|
case "ewnl":
|
|
|
|
siteId = site.SITE_EWNL
|
|
|
|
case "vkvnl":
|
|
|
|
siteId = site.SITE_VKVNL
|
|
|
|
default:
|
|
|
|
log.Fatal(errors.New("unknown site"))
|
|
|
|
}
|
|
|
|
|
2020-12-04 12:50:20 +01:00
|
|
|
// initialize site
|
2020-12-31 13:28:09 +01:00
|
|
|
config, err := site.NewSiteConfig(siteId)
|
2020-12-29 15:34:55 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
s, err := site.New(config, *resources)
|
2020-12-04 12:50:20 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-12-04 16:52:25 +01:00
|
|
|
// add statics
|
|
|
|
staticNames, err := ioutil.ReadDir(*statics)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
for _, sn := range staticNames {
|
|
|
|
if sn.IsDir() {
|
|
|
|
s.AddStaticPage(filepath.Join(*statics, sn.Name()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-04 12:50:20 +01:00
|
|
|
// add content
|
|
|
|
for _, cp := range strings.Split(*content, ",") {
|
|
|
|
log.Printf("checking %s for content\n", cp)
|
|
|
|
if err := filepath.Walk(cp, func(path string, info os.FileInfo, err error) error {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if !info.IsDir() && filepath.Ext(path) == ".adoc" {
|
|
|
|
s.AddFilePost(path)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// render site
|
|
|
|
if err := s.RenderHTML(*public); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|