diff --git a/example/pages/index.html b/example/pages/index.html index d2c551f..bcdc4ec 100644 --- a/example/pages/index.html +++ b/example/pages/index.html @@ -1,3 +1,5 @@

Your Content Here

Put your stuff here.

+ +

Hello

diff --git a/example/ssgod.toml b/example/ssgod.toml index 875dd8e..0fb1e95 100644 --- a/example/ssgod.toml +++ b/example/ssgod.toml @@ -1,4 +1,5 @@ + views = "pages" layout = "pages/layouts/main.html" target = "public" -watch_delay = "1s" +watch_delay = "500ms" diff --git a/main.go b/main.go index 5e1c59c..43588a4 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,13 @@ import ( "github.com/fsnotify/fsnotify" ) +var DEFAULT_CONFIG = ` +views = "pages" +layout = "pages/layouts/main.html" +target = "public" +watch_delay = "500ms" +` + func Fail(err error, format string, v ...any) error { err_format := fmt.Sprintf("ERROR: %v; %s", err, format) log.Printf(err_format, v...) @@ -206,15 +213,34 @@ func WatchDir() { <-make(chan struct{}) } +func InitConfig(config_file string) { + _, err := os.Stat(config_file) + + if os.IsNotExist(err) { + out, err := os.OpenFile(config_file, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) + if err != nil { log.Fatalf("error opening %s", config_file) } + defer out.Close() + out.WriteString(DEFAULT_CONFIG) + } else { + log.Fatalf("there's already a %s file here", config_file); + } +} + func main() { - config.Load("ssgod.toml") + var config_file string - watch := flag.Bool("watch", false, "Watch the views directory for changes") + flag.StringVar(&config_file, "config", "ssgod.toml", ".toml config file to use") flag.Parse() + command := flag.Arg(0) - if *watch { + switch command { + case "watch": + config.Load(config_file) WatchDir() - } else { + case "init": + InitConfig(config_file) + default: + config.Load(config_file) RenderPages(); } }