mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-10-30 01:13:08 +00:00
54 lines
935 B
Go
54 lines
935 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
)
|
|
|
|
func main() {
|
|
if err := run(); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func run() error {
|
|
var format string
|
|
flag.StringVar(&format, "format", "gemini", "output format to use. Supported formats include gemini and html")
|
|
flag.Parse()
|
|
|
|
// Load config
|
|
cfg, err := LoadConfig("config.toml")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := cfg.LoadTemplates("layouts"); err != nil {
|
|
return err
|
|
}
|
|
|
|
var output Format
|
|
switch format {
|
|
case "gemini":
|
|
output = FormatFunc(FormatGemini)
|
|
case "html":
|
|
output = FormatFunc(FormatHTML)
|
|
default:
|
|
log.Fatalf("unknown output format %q", format)
|
|
}
|
|
|
|
// Load content
|
|
dir := NewDir("")
|
|
if err := dir.read("content", ""); err != nil {
|
|
return err
|
|
}
|
|
dir.sort()
|
|
// Manipulate content
|
|
if err := dir.manipulate(cfg); err != nil {
|
|
return err
|
|
}
|
|
// Write content
|
|
if err := dir.write("public", output, cfg); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|