diff --git a/.gitignore b/.gitignore index 9c9db0f..6c98c2a 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ coverage/* .venv *.gz public +ssgod diff --git a/README.md b/README.md index f127130..6f2b0df 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,9 @@ SSG is a Static Site Generator that is only a Static Site Generator. No resumes ## Current Features +> __WARNING__: I changed the file format to .json to reduce dependencies and also made it a hidden +> `.ssgod.json` file to match other tools. + * Simply converts dirs to other dir. * Default Go templates, and markdown. * Watches the dir and reruns the build when there's a change. @@ -38,7 +41,7 @@ go tool ssgod ## Usage These instructions assume you're running the tool using `go tool`. If not then, I mean, you're a -smart person right? Create a default `ssgod.toml` config: +smart person right? Create a default `.ssgod.json` config: ```shell go tool ssgod init @@ -47,7 +50,7 @@ go tool ssgod init You can change the config file name with the `--config` option: ```shell -go tool ssgod --config mysite.toml init +go tool ssgod --config mysite.json init ``` This option is available for all commands, so if you want to init a different config file then do as @@ -78,15 +81,16 @@ to prevent running the render too often. > into `static/` so `ssgod` can faithfully recreate your `public/`. If you want to have `ssgod` sync a `static` directory then you have to uncomment a line in the -`ssgod.toml` file to enable `sync_dir` as an option: - -```toml -views = "pages" -layout = "pages/layouts/main.html" -target = "public" -watch_delay = "500ms" -# comment this out to sync static -sync_dir = "static" +`.ssgod.json` file to enable `sync_dir` as an option: + +```json +{ + "views": "pages", + "layout": "pages/layouts/main.html", + "target": "public", + "watch_delay": "500ms", + "sync_dir": "static" +} ``` In this example I've removed the comment. Once you do that `ssgod` will then __remove your diff --git a/config/loader.go b/config/loader.go index 9edf0e7..cdf9968 100644 --- a/config/loader.go +++ b/config/loader.go @@ -2,29 +2,28 @@ package config import ( "log" - "github.com/BurntSushi/toml" + "encoding/json" + "os" ) type config struct { - Views string `toml:"views"` - Layout string `toml:"layout"` - Target string `toml:"target"` - WatchDelay string `toml:"watch_delay"` - SyncDir string `toml:"sync_dir"` + Views string `json:"views"` + Layout string `json:"layout"` + Target string `json:"target"` + WatchDelay string `json:"watch_delay"` + SyncDir string `json:"sync_dir"` } var Settings config func Load(path string) { - metadata, err := toml.DecodeFile(path, &Settings) + config, err := os.ReadFile(path) + if err != nil { + log.Fatalf("invalid config path: %s", path) + } - if err != nil { - log.Fatalf("error loading config.toml: %v", err) - } - - bad_keys := metadata.Undecoded() - - if len(bad_keys) > 0 { - log.Fatalf("unknown configuration keys: %v", bad_keys); - } + err = json.Unmarshal(config, &Settings) + if err != nil { + log.Fatalf("json format error:", err) + } } diff --git a/example/.ssgod.json b/example/.ssgod.json new file mode 100644 index 0000000..9b6d393 --- /dev/null +++ b/example/.ssgod.json @@ -0,0 +1,7 @@ +{ + "views": "pages", + "layout": "pages/layouts/main.html", + "target": "public", + "watch_delay": "500ms", + "sync_dir": "static" +} diff --git a/example/ssgod.toml b/example/ssgod.toml deleted file mode 100644 index 34438b9..0000000 --- a/example/ssgod.toml +++ /dev/null @@ -1,6 +0,0 @@ -views = "pages" -layout = "pages/layouts/main.html" -target = "public" -watch_delay = "500ms" -# comment this out, WARNING this deletes target! -# sync_dir = "static" diff --git a/go.mod b/go.mod index d621bf4..8f2e3d9 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module lcthw.dev/go/ssgod go 1.24.2 require ( - github.com/BurntSushi/toml v1.5.0 github.com/fsnotify/fsnotify v1.9.0 github.com/stretchr/testify v1.10.0 github.com/yuin/goldmark v1.7.13 diff --git a/go.sum b/go.sum index 0ed46fc..6651ffb 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,3 @@ -github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg= -github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= diff --git a/main.go b/main.go index 5f06db8..1f339bb 100644 --- a/main.go +++ b/main.go @@ -15,16 +15,11 @@ import ( "strings" "text/template" "time" + _ "embed" ) -var DEFAULT_CONFIG = ` -views = "pages" -layout = "pages/layouts/main.html" -target = "public" -watch_delay = "500ms" -# comment this out, WARNING this deletes target! -# sync_dir = "static" -` +//go:embed example/.ssgod.json +var DEFAULT_CONFIG string func Fatal(err error, format string, v ...any) { err_format := fmt.Sprintf("ERROR: %v; %s", err, format) @@ -66,7 +61,7 @@ func RenderTemplate(out io.Writer, embed string, variables any) error { func RenderMarkdown(path string, target_path string, page_id string) error { log.Printf("MARKDOWN: %s -> %s", path, target_path) - out, err := os.OpenFile(target_path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) + out, err := os.Create(target_path) defer out.Close() if err != nil { @@ -94,7 +89,7 @@ func RenderMarkdown(path string, target_path string, page_id string) error { func RenderHTML(source_path string, target_path string, page_id string) error { log.Printf("RENDER: %s -> %s", source_path, target_path) - out, err := os.OpenFile(target_path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) + out, err := os.Create(target_path) defer out.Close() html_content, err := os.ReadFile(source_path) @@ -328,13 +323,14 @@ 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) + out, err := os.Create(config_file) if err != nil { log.Fatalf("error opening %s", config_file) } defer out.Close() out.WriteString(DEFAULT_CONFIG) + log.Println("new config written to:", config_file) } else { log.Fatalf("there's already a %s file here", config_file) } @@ -343,7 +339,7 @@ func InitConfig(config_file string) { func main() { var config_file string - flag.StringVar(&config_file, "config", "ssgod.toml", ".toml config file to use") + flag.StringVar(&config_file, "config", ".ssgod.json", ".json config file to use") flag.Parse() command := flag.Arg(0)