A basic init command that will generate a starter .toml file and the ability to change the config used with --config. MUST COME BEFORE COMMAND.

master
Zed A. Shaw 2 weeks ago
parent 415b01c78d
commit 6ac8620053
  1. 2
      example/pages/index.html
  2. 3
      example/ssgod.toml
  3. 34
      main.go

@ -1,3 +1,5 @@
<h1>Your Content Here</h1>
<p>Put your stuff here.</p>
<h3>Hello</h3>

@ -1,4 +1,5 @@
views = "pages"
layout = "pages/layouts/main.html"
target = "public"
watch_delay = "1s"
watch_delay = "500ms"

@ -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();
}
}

Loading…
Cancel
Save