2020-09-22 22:42:14 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-09-29 01:54:48 +02:00
|
|
|
"flag"
|
2020-09-22 22:42:14 +02:00
|
|
|
"log"
|
2020-09-29 01:54:48 +02:00
|
|
|
)
|
|
|
|
|
2020-09-22 22:42:14 +02:00
|
|
|
func main() {
|
2020-10-01 03:57:59 +02:00
|
|
|
if err := run(); err != nil {
|
2020-09-22 22:42:14 +02:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-20 18:07:38 +01:00
|
|
|
func run() error {
|
2021-02-27 21:34:05 +01:00
|
|
|
var format string
|
|
|
|
flag.StringVar(&format, "format", "gemini", "output format to use. Supported formats include gemini and html")
|
2020-11-20 18:07:38 +01:00
|
|
|
flag.Parse()
|
2020-10-01 03:57:59 +02:00
|
|
|
|
2020-11-20 18:07:38 +01:00
|
|
|
// Load config
|
2021-03-20 07:02:36 +01:00
|
|
|
cfg, err := LoadConfig("config.toml")
|
|
|
|
if err != nil {
|
2020-11-20 18:07:38 +01:00
|
|
|
return err
|
|
|
|
}
|
2021-03-20 07:18:15 +01:00
|
|
|
if err := cfg.LoadTemplates("templates"); err != nil {
|
2020-11-20 18:07:38 +01:00
|
|
|
return err
|
2020-10-01 04:14:10 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 03:53:16 +01: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 03:57:59 +02:00
|
|
|
// Load content
|
|
|
|
dir := NewDir("")
|
2021-02-28 03:39:13 +01:00
|
|
|
if err := dir.read("content", ""); err != nil {
|
2020-09-22 22:42:14 +02:00
|
|
|
return err
|
|
|
|
}
|
2020-10-01 03:57:59 +02:00
|
|
|
dir.sort()
|
|
|
|
// Manipulate content
|
2020-11-20 18:07:38 +01:00
|
|
|
if err := dir.manipulate(cfg); err != nil {
|
2020-09-22 22:42:14 +02:00
|
|
|
return err
|
|
|
|
}
|
2020-10-01 03:57:59 +02:00
|
|
|
// Write content
|
2021-02-28 03:39:13 +01:00
|
|
|
if err := dir.write("public", output, cfg); err != nil {
|
2020-09-22 22:42:14 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|