2020-12-04 12:50:20 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2020-12-04 16:52:25 +01:00
|
|
|
"io/ioutil"
|
2020-12-04 12:50:20 +01:00
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"git.sr.ht/~ewintr/shitty-ssg/site"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
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-04 16:52:25 +01:00
|
|
|
if *resources == "" || *content == "" || *public == "" || *statics == "" {
|
2020-12-04 12:50:20 +01:00
|
|
|
log.Fatal("missing parameter")
|
|
|
|
}
|
|
|
|
|
|
|
|
// initialize site
|
|
|
|
s, err := site.New(*resources)
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|