|
|
|
|
@ -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) |
|
|
|
|
|
|
|
|
|
|