package generate import ( "flag" "fmt" "git.gutmet.org/goutil.git" "git.gutmet.org/simpleserver.git" "git.gutmet.org/wombat.git/blog" "git.gutmet.org/wombat.git/converter" "git.gutmet.org/wombat.git/gallery" "git.gutmet.org/wombat.git/initer" "git.gutmet.org/wombat.git/site" "git.gutmet.org/wombat.git/splitter" "os" ) func removeAll(path string) { err := os.RemoveAll(path) if err != nil { fmt.Fprintln(os.Stderr, err) } } func clean() { removeAll("stage1") removeAll("stage2") } func stage1() { goutil.CopyDirsLinkFiles("stage0", "stage1") mdfiles := goutil.RecListFilesExt("stage1", ".md") htmlfrags := goutil.RecListFilesExt("stage1", ".html") splitter.SplitAll(append(mdfiles, htmlfrags...)) converter.ConvertAll(mdfiles) } func blogs() []string { dirs, err := goutil.DirsWithPrefix("stage0", "blog") if err != nil { fmt.Fprintln(os.Stderr, err) } return dirs } func stage2() { goutil.CopyDirsLinkFiles("stage1", "stage2") site.Generate() for _, blogdir := range blogs() { blog.Generate(blogdir) } descfiles := goutil.RecListFilesExt("stage2", ".desc") for _, f := range descfiles { err := os.Remove(f) if err != nil { fmt.Fprintln(os.Stderr, err) } } os.Remove("stage2/README") } func Generate(f GenerateFlags) error { initer.InitializedOrDie() clean() gallery.Generate(gallery.Flags{}) stage1() stage2() if !f.Noserve { simpleserver.Serve("stage2") } return nil } type GenerateFlags struct { Noserve bool } func Command() (goutil.CommandFlagsInit, goutil.CommandFunc) { f := GenerateFlags{} flagsInit := func(s *flag.FlagSet) { s.BoolVar(&f.Noserve, "noserve", false, "don't start webserver after generating") } return flagsInit, func([]string) error { return Generate(f) } }