2020-09-22 20:42:14 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-09-28 23:54:48 +00:00
|
|
|
"flag"
|
2020-09-22 20:42:14 +00:00
|
|
|
"log"
|
2020-09-28 23:54:48 +00:00
|
|
|
)
|
|
|
|
|
2020-09-22 20:42:14 +00:00
|
|
|
func main() {
|
2020-10-01 01:57:59 +00:00
|
|
|
if err := run(); err != nil {
|
2020-09-22 20:42:14 +00:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-20 17:07:38 +00:00
|
|
|
func run() error {
|
2021-02-27 20:34:05 +00:00
|
|
|
var format string
|
|
|
|
flag.StringVar(&format, "format", "gemini", "output format to use. Supported formats include gemini and html")
|
2020-11-20 17:07:38 +00:00
|
|
|
flag.Parse()
|
2020-10-01 01:57:59 +00:00
|
|
|
|
2020-11-20 17:07:38 +00:00
|
|
|
// Load config
|
2021-03-20 06:02:36 +00:00
|
|
|
cfg, err := LoadConfig("config.toml")
|
|
|
|
if err != nil {
|
2020-11-20 17:07:38 +00:00
|
|
|
return err
|
|
|
|
}
|
2021-02-28 02:39:13 +00:00
|
|
|
if err := cfg.LoadTemplates("layouts"); err != nil {
|
2020-11-20 17:07:38 +00:00
|
|
|
return err
|
2020-10-01 02:14:10 +00:00
|
|
|
}
|
|
|
|
|
2021-02-28 02:53:16 +00:00
|
|
|
var output Format
|
|
|
|
switch format {
|
|
|
|
case "gemini":
|
|
|
|
output = FormatFunc(FormatGemini)
|
|
|
|
case "html":
|
|
|
|
output = FormatFunc(FormatHTML)
|
|
|
|
default:
|
|
|
|
log.Fatalf("unknown output format %q", format)
|
|
|
|
}
|
|
|
|
|
2020-10-01 01:57:59 +00:00
|
|
|
// Load content
|
|
|
|
dir := NewDir("")
|
2021-02-28 02:39:13 +00:00
|
|
|
if err := dir.read("content", ""); err != nil {
|
2020-09-22 20:42:14 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-10-01 01:57:59 +00:00
|
|
|
dir.sort()
|
|
|
|
// Manipulate content
|
2020-11-20 17:07:38 +00:00
|
|
|
if err := dir.manipulate(cfg); err != nil {
|
2020-09-22 20:42:14 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-10-01 01:57:59 +00:00
|
|
|
// Write content
|
2021-02-28 02:39:13 +00:00
|
|
|
if err := dir.write("public", output, cfg); err != nil {
|
2020-09-22 20:42:14 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|